2016-06-01 103 views
0

所以我使用mysqli之前我的查询,现在我将它转换为mysqli编写。我试图用上传图像更新特定的数据,我不知道为什么我得到的错误mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in line 30以及我怎样才能在mysqli查询中执行查询如mysqli_query($conn, $query)如何使用mysqli准备数据库更新?

以下是我的更新查询的代码:

if (isset($_POST['submit'])) { 

    $imageName = mysqli_real_escape_string($conn, $_FILES["latest_photo"]["name"]); 
    $imageData = mysqli_real_escape_string($conn, file_get_contents($_FILES["latest_photo"]["tmp_name"])); 
    $imageType = mysqli_real_escape_string($conn, $_FILES["latest_photo"]["type"]); 

     if (substr($imageType, 0,5) == "image") { 

      $query = "UPDATE `crew_info` SET `updated_photo` = ? WHERE `id` = ?"; 
      $stmt = mysqli_prepare($conn, $query); 
      mysqli_stmt_bind_param($stmt, 'ss', $imageData, $_GET['id']); 
      mysqli_stmt_execute($stmt); 
      mysqli_stmt_bind_result($stmt, $id, $updated_photo);  

      //HOW CAN I EXECUTE THE QUERY HERE? 
      echo "Image Uploaded"; 

     } 

     else { 

      echo "Image is not uploaded!"; 

     } 

} 

在上面的代码中,有关于如何执行查询的注释行。我怎样才能做到这一点?感谢你们

编辑:

此外,当我点击上传按钮,它说,图像上传,但不会出现在数据库中。这是为什么?

+0

在我的'mysqli_stmt_bind_result()',我试图包括该表中的所有列。 –

+0

您正在运行不返回任何结果的更新语句,这就是您无法使用'mysqli_stmt_bind_result'绑定结果的原因。如果你想要返回结果,那么你将需要第二条语句,如'SELECT crew_info,updated_photo WHERE id =?' –

+0

对不起,我是mysqli新手准备的 –

回答

0
//for procedural way 
    $query = "UPDATE `crew_info` SET `updated_photo` = ? WHERE `id` = ?"; 
    $stmt = mysqli_prepare($conn, $query); 
    // you should use i instead of s for id 
    mysqli_stmt_bind_param($stmt, 'si', $imageData, $_GET['id']); 
    mysqli_stmt_execute($stmt); 

//try this out in object oriented 
    $query = "UPDATE `crew_info` SET `updated_photo` = ? WHERE `id` = ?"; 
    $stmt = mysqli_prepare($conn, $query); 
    $stmt->bind_param("si", $imageData, $id); 
    $imageData=$imageName ; 
    $id=$_GET['id']; 
    $stmt->execute(); 
+0

让我知道如果它不适合你 –

+0

如何在程序中做? –

+0

好吧,我会改变我的答案等一下 –