Jump to content

Mysql BLOB syntax error


voip03

Recommended Posts

I am learning Mysql BLOB from

http://www.techcubetalk.com/2009/01/tutorial-on-how-to-store-images-in-mysql-blob-field/

 

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.

 

<?
require('config.php');


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);
		if(!$res)
		{  	die(" error: <br/>". mysql_error() ); }

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

          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
https://forums.phpfreaks.com/topic/243928-mysql-blob-syntax-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.