gpt4 book ai didi

php - 使用PHP错误将图像存储在数据库中

转载 作者:可可西里 更新时间:2023-11-01 07:55:55 27 4
gpt4 key购买 nike

我想在 PHP 中制作个人资料页面,我应该在其中显示登录用户的信息,包括为此目的的个人资料照片。我想将上传的图像存储在数据库中。我已经编写了脚本,但它在 SQL 语句中给了我一些错误。

我的 php 脚本

<?php
include("configdb.php");
function GetImageExtension($imagetype)
{
if(empty($imagetype)) return false;
switch($imagetype)
{
case 'image/bmp': return '.bmp';
case 'image/gif': return '.gif';
case 'image/jpeg': return '.jpg';
case 'image/png': return '.png';
default: return false;
}
}
if (!empty($_FILES["uploadedimage"]["name"])) {
$file_name=$_FILES["uploadedimage"]["name"];
$temp_name=$_FILES["uploadedimage"]["tmp_name"];
$imgtype=$_FILES["uploadedimage"]["type"];
$ext= GetImageExtension($imgtype);
$imagename=date("d-m-Y")."-".time().$ext;
$target_path = "../Photos/".$imagename;
if(move_uploaded_file($temp_name, $target_path)) {
$query_upload="INSERT into 'images_tbl' ('images_path','submission_date') VALUES
('".$target_path."','".date("Y-m-d")."')";
mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error());
}else{
exit("Error While uploading image on the server");
}
}
?>;

出现以下错误

error in INSERT into 'images_tbl' ('images_path','submission_date') VALUES ('../Photos/03-10-2016-1475478958.jpg','2016-10-03') == ----> You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''images_tbl' ('images_path','submission_date') VALUES ('../Photos/03-10-2016-14' at line 1**

最佳答案

你正在混合 Mysqli 和 Mysql 试试这样

 $query_upload="INSERT into images_tbl (`images_path`,`submission_date`) VALUES
('".$target_path."','".date("Y-m-d")."')";
mysqli_query($conn,$query_upload) or die("error in $query_upload == ----> ".mysqli_error($conn));

代替

 $query_upload="INSERT into 'images_tbl' ('images_path','submission_date') VALUES
('".$target_path."','".date("Y-m-d")."')";
mysql_query($query_upload) or die("error in $query_upload == ----> ".mysql_error());

关于php - 使用PHP错误将图像存储在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39826394/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com