我正在尝试将图片上传到我的数据库中。
该脚本工作正常,不显示任何错误消息。该脚本成功上传到我的服务器中名为' profilepics'的目录。但它无法使用图像信息更新数据库,没有错误,当我回显出脚本时,一切正常,如会话变量,图像名称字段等。
这是我的问题:
$query = "UPDATE members SET image='$pic' WHERE memberID='" . $_SESSION['user'] . "'";
$result = mysqli_query($connection, $query) or exit ("Error in query: $query. ".mysqli_error());
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else { //Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
答案 0 :(得分:1)
UPDATE
仅在您拥有要更新的现有行时使用。
因此,当您正在插入新行时,请使用INSERT INTO
。
使用您的查询INSERT INTO QUERY
的示例:
$query = "INSERT INTO members(`image`) VALUES ('". $pic . "')";
答案 1 :(得分:0)
再次感谢