在我的SQL查询中将图像插入MySQL数据库时出现了一些错误


There is some error in my SQL query for inserting image to MySQL database

我在MySQL数据库中插入图像的SQL查询中出错。

当我试图保存图像时,在插入图像的SQL查询中出现错误。错误是这个

您的SQL语法有错误;查看与MySQL服务器版本相对应的手册,了解在'2附近使用的正确语法(.?/279<<

<!DOCTYPE html>
<html>
<body>
    <form action="http://localhost/upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
      <input type="file" name="image" id="fileToUpload">
      <input type="submit" value="Upload Image" name="submit">
    </form>
</body>
</html>
<?php
  mysql_connect("localhost","root","") or die("not conected");
  mysql_select_db("image") or die("not selected");
  $file_name=$_FILES['image']['name'];
  $myfile=file_get_contents($_FILES['image']['tmp_name']);
  $q="INSERT INTO imagee(image_id,image_name,image)
                  VALUES('','$file_name','$myfile')";
  mysql_query($q) or die(mysql_error());
?>

<form action="phpfilename.php" method="post" 
       enctype="multipart/form-data">
<input  type="file" name="file" id="file" />	
<input type="submit" value="Upload Image" name="submit">
	
$file=$_FILES['file']['name'];
$dest="uploads/$file";
$src=$_FILES['file']['tmp_name'];
move_uploaded_file($src,$dest);
$result=mysql_query("insert into tablename(dbfieldname) values('$dest')");

echo $myfile;

看看这些数据看起来怎么样。

你可能想要

base64_encode(file_get_contents($_FILES['image']['tmp_name'])) 

在使用到INSERT查询之前。

http://php.net/manual/en/function.base64-encode.php