Jump to content

Mysql BLOB syntax error


Recommended Posts

I am learning Mysql BLOB from



And I am getting error when I add ‘img_data’ and $imgContent  in the  insert  statement

‘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 '' at line 2’

This is my code.



if(isset($_REQUEST[submit]) && $_FILES[imgfile][size] > 0)
          $fileName    = $_FILES[imgfile][name]; // image file name
          $tmpName     = $_FILES[imgfile][tmp_name]; // name of the temporary stored file name
          $fileSize    = $_FILES[imgfile][size]; // size of the uploaded file
          $fileType    = $_FILES[imgfile][type]; // file type

		  $fp = fopen($tmpName, "r"); // open a file handle of the temporary file
          $imgContent  = fread($fp, filesize($tmpName)); // read the temp file
          fclose($fp); // close the file handle

          $sql = "INSERT INTO img_tbl (img_name,img_type,img_size,img_data)
                        VALUES ('$fileName','$fileType','$fileSize','$imgContent')";

		$res = mysql_query($sql);
		{  	die(" error: <br/>". mysql_error() ); }

          $imgid = mysql_insert_id(); // autoincrement id of the uploaded entry

          echo "<br>Image successfully uploaded to database<br>";
  		  echo "<a href=/jquery/BLOB/viewimage.php?id=$imgid\>View Image</a>"; 
else die("You have not selected any image");



Link to comment
Share on other sites

have you tried printing the $sql variable to the screen to see if it looks ok?


my guess is that the contents of the $imgContent variable is causing the problem. Maybe try calling mysql_real_escape_string() in it before inserting in into the query string

Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.