我试图能够将图像上传到我的网站上,并将文件路径放在与用户帐户相关的行上的数据库中。一切似乎都很好,但当我尝试上传图片时,我收到以下错误:"错误:未知列'图片'在'字段列表'"。我理解这意味着列图像正在尝试在数据库中访问,但我不知道为什么它正在寻找该列,我没有在sql中指定它。任何帮助将不胜感激。
$ID = $_SESSION['number'];
$uploadDir = 'images/profileimages/'; //Image Upload Folder
if(isset($_POST['Submit']))
{
$fileName = $_FILES['Photo']['name'];
$tmpName = $_FILES['Photo']['tmp_name'];
$fileSize = $_FILES['Photo']['size'];
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
}
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$sql="UPDATE users SET profileimage= $filePath WHERE ID = '$ID'";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
header('location: account.php');
mysqli_close($con);
?>
答案 0 :(得分:3)
将您的查询重写为,
$sql="UPDATE users SET profileimage= '$filePath' WHERE ID = '$ID'";
这可能会消除您的错误。