更新查询的准备语句不起作用

时间:2021-09-05 21:18:01

My update query is not executing. I have checked all the field headings in the dog table and they match the field headings I put in the query.

我的更新查询未执行。我检查了狗表中的所有字段标题,它们与我在查询中输入的字段标题相匹配。

It was working fine till I added the dogImage field. However I want a user to be able to update a dog image as well. The dogImageUpload.php file runs a check on the image uploaded using a fle input type and then adds it to an uploads folder.

在添加dogImage字段之前,它工作正常。但是我希望用户也能够更新狗图像。 dogImageUpload.php文件对使用文件输入类型上传的图像运行检查,然后将其添加到uploads文件夹。

Please help. By the way this is my first stack overflow post so please excuse any errors or lack of ability to explain my code.

请帮忙。顺便说一下这是我的第一个堆栈溢出帖子,所以请原谅任何错误或缺乏解释我的代码的能力。

<?php

    session_start();
    if(!isset($_SESSION['staffID'])){
        Header("Location:../../html/vetLoginForm.html");
        die();
    }

    $id         = $_POST['id'];
    $newName    = $_POST['newName'];
    $newBreed   = $_POST['newBreed'];
    $newGender  = $_POST['newGender'];
    $newDC      = $_POST['newDC'];
    $newHeight  = $_POST['newHeight'];
    $newWeight  = $_POST['newWeight'];
    $newGenDesc = $_POST['newGenDesc'];
    $newDF      = $_POST['newDF'];
    $newStatus  = $_POST['newStatus'];

    //connect to db
    require('../../services/connection.php');

    //file that uploads image to folder in the directory
    include("dogImgUpload.php");

    //run update query
    if($updateDog = mysqli_prepare($con, "UPDATE dog SET 
                                     name =?,
                                     breed =?,
                                     gender =?,
                                     dominantColour =?,
                                     height =?,
                                     weight =?,
                                     generalDescription =?,
                                     dateFound =?,
                                     dogImage =?,
                                     status =?,
                                     WHERE dogID =?")){
        mysqli_stmt_bind_param($updateDog,"ssssddssssi", $newName, $newBreed, $newGender, $newDC, $newHeight, $newWeight, $newGenDesc, $newDF, $imgFileName, $newStatus, $id);
        mysqli_stmt_execute($updateDog);
        mysqli_stmt_close($updateDog);


        include("updateSuccessful.php");
        mysqli_error($con);
    }else{
        echo "Error updating record" . mysqli_error($con);
    }


    ?>

2 个解决方案

#1


0  

You have an extra comma at the end of the set column (remove it)

在set列的末尾有一个额外的逗号(删除它)

if($updateDog = mysqli_prepare($con, "UPDATE dog SET 
                                 name =?,
                                 breed =?,
                                 gender =?,
                                 dominantColour =?,
                                 height =?,
                                 weight =?,
                                 generalDescription =?,
                                 dateFound =?,
                                 dogImage =?,
                                 status =?
                                 WHERE dogID =?")){

#2


0  

mysqli_stmt_bind_param($updateDog,"ssssddssssi",

I put the datatype for the value to be inserted into the status column as a string. The status column in my database, however, carries the int datatype.

我将要插入到状态列中的值的数据类型作为字符串。但是,我的数据库中的status列带有int数据类型。

#1


0  

You have an extra comma at the end of the set column (remove it)

在set列的末尾有一个额外的逗号(删除它)

if($updateDog = mysqli_prepare($con, "UPDATE dog SET 
                                 name =?,
                                 breed =?,
                                 gender =?,
                                 dominantColour =?,
                                 height =?,
                                 weight =?,
                                 generalDescription =?,
                                 dateFound =?,
                                 dogImage =?,
                                 status =?
                                 WHERE dogID =?")){

#2


0  

mysqli_stmt_bind_param($updateDog,"ssssddssssi",

I put the datatype for the value to be inserted into the status column as a string. The status column in my database, however, carries the int datatype.

我将要插入到状态列中的值的数据类型作为字符串。但是,我的数据库中的status列带有int数据类型。