Babar Junaid Babar Junaid - 6 months ago 8
HTML Question

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

I have an error in my SQL query for inserting image in database of MySQL.

When I try to save image error occur in SQL query for inserting image. The error is this


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 '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());
?>

Answer

<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')");