PHP参数没有正确绑定以使用mySQL

时间:2018-06-17 20:08:29

标签: php mysql mysqli

我没有找到适合我的stackoverflow的答案,所以当我使用PHP将数据保存到mySQL时,我添加了2个参数。保存imgfile参数时,只保存参数名称。

参数:

$stmt->bindParam(':imgfile', $newfilename);

更新后在数据库中:

---------------------------
 ID   imgfile
---------------------------
  1   :imgfile
---------------------------

期待看到的内容:

---------------------------
  ID   imgfile
---------------------------
   1   45678_profile.png
---------------------------

我的整个代码(我将id设置为1,存在的用户,如果PHP无法获取ID):

     if (move_uploaded_file($_FILES["file"]["tmp_name"], "/home1/bubos/public_html/homework/images/pfimages/" . $newfilename)) {
        $stmt = $conn->prepare("UPDATE `users` SET `profileimg` = ':imgfile'  WHERE `users`.`id` = 1");
        $stmt->bindParam(':id', $_SESSION['user_id']);
        $stmt->bindParam(':imgfile', $newfilename );

if ( $stmt = $conn->prepare("UPDATE `users` SET `profileimg` = ':imgfile'  WHERE `users`.`id` = 1")) {
    $stmt->execute();
    $message = "Image was uploaded to server and set successfully!";
} else {
    $message = "Image uploaded to server, but error occurred on image setting!";
}
} else {
    $message =  "Error on image uploading to server!";
}

有谁能说我该如何解决?

0 个答案:

没有答案