我想在PHP中创建个人资料页面,我应该显示登录用户的信息,包括用于此目的的个人资料照片。我想将上传的图像存储在数据库中。我写了脚本,但它给了我SQL语句中的一些错误。图像存储在数据库中使用PHP错误
我的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");
}
}
?>;
我得到了以下错误在INSERT
错误为 'images_tbl'( 'images_path', 'submission_date')VALUES(” ../Photos/03- 10-2016-1475478958.jpg','2016-10-03')== ---->你的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,以在''images_tbl'('images_path','submission_date')附近使用正确的语法VALUES('../Photos/03-10-2016-14'in line 1 * *
爵士仍然有在INSERT误差为'images_tbl'('images_path','submission_date')VALUES(” ../Photos/03-10-2016-1475479781.jpg','2016-10-03 ')== ---->没有选择数据库 –
您是否也可以共享'configdb.php'代码 – RamRaider
<?php \t \t $ servername =“localhost”; \t $ username =“root”; \t $ password =“”; \t $ dbname =“firstdb”; \t $ conn = mysqli_connect($ servername,$ username,$ password,$ dbname); ($ conn-> connect_error) \t如果($ conn-> connect_error) \t { \t die(“connection failed”。$ conn-> connect_error); \t} \t回声“连接成功”; \t \t ?> –