我正在嘗試從HTML表單中保存數(shù)據(jù)庫中的圖像。我編寫了PHP代碼來完成這項(xiàng)任務(wù)。該程序沒有生成任何錯(cuò)誤消息,也沒有在MySQL數(shù)據(jù)庫中插入圖像數(shù)據(jù)。請檢查一下。在這里,我分享我的代碼摘錄。 /*-------------------
IMAGE QUERY
---------------*/
$file =$_FILES['image']['tmp_name'];
if(!isset($file))
{
echo 'Please select an Image';
}
else
{
$image_check = getimagesize($_FILES['image']['tmp_name']);
if($image_check==false)
{
echo 'Not a Valid Image';
}
else
{
$image = file_get_contents ($_FILES['image']['tmp_name']);
$image_name = $_FILES['image']['name'];
if ($image_query = mysql_query ("insert into product_images values (1,'$image_name',$image )"))
{
echo $current_id;
//echo 'Successfull';
}
else
{
echo mysql_error();
}
}
}
/*-----------------
IMAGE QUERY END
---------------------*/
<form action='insert_product.php' method='POST' enctype='multipart/form-data' ></br>
File : <input type='file' name= 'image' >
</form>錯(cuò)誤消息:您的SQL語法有錯(cuò)誤;請檢查與MySQL服務(wù)器版本相對應(yīng)的手冊,以獲得在第1行使用Next‘的正確語法。
如何使用PHP代碼將圖像上傳到MySQL數(shù)據(jù)庫
慕標(biāo)琳琳
2019-07-13 15:19:11