voip03 Posted August 5, 2011 Share Posted August 5, 2011 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/243928-mysql-blob-syntax-error/ Share on other sites More sharing options...
@ Posted August 5, 2011 Share Posted August 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/243928-mysql-blob-syntax-error/#findComment-1252520 Share on other sites More sharing options...
voip03 Posted August 5, 2011 Author Share Posted August 5, 2011 Thank u'@' Quote Link to comment https://forums.phpfreaks.com/topic/243928-mysql-blob-syntax-error/#findComment-1252529 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.