tahakirmani Posted July 18, 2013 Share Posted July 18, 2013 I am trying to save images in my database from HTML form. I have written PHP code to accomplish this task. Its giving me the following error message,and not inserting data in the database. Kindly check it. Here i am sharing a excerpt from my code. I am using BLOB for image. /*------------------- IMAGE QUERY ---------------*/ $file =$_FILES['image']['tmp_name']; if(!isset($file)) { echo 'Please select an Image'; } else { $image_check= getimagesize($_FILES['image']['tmp_name']); if($image_check==false) { echo 'Not a Valid Image'; } else { $image =file_get_contents ($_FILES['image']['tmp_name'] ); $image_name =$_FILES['image']['name']; if ($image_query =mysql_query ("insert into product_images values (1,'$image_name',$image )")) { echo $current_id; //echo 'Successfull'; } else { echo mysql_error(); } } } /*----------------- IMAGE QUERY END ---------------------*/ <form action='insert_product.php' method='POST' enctype='multipart/form-data' ></br> File : <input type='file' name= 'image' > </form> Error Message Error Message 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 1 Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted July 18, 2013 Share Posted July 18, 2013 why on earth would you want to put the actual images into your database? Quote Link to comment Share on other sites More sharing options...
Tweezy Posted July 18, 2013 Share Posted July 18, 2013 You have wrapped it in <?php ?> tags right? Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 19, 2013 Share Posted July 19, 2013 "insert into product_images values (1, '$image_name', '$image')" Quote Link to comment Share on other sites More sharing options...
DavidAM Posted July 19, 2013 Share Posted July 19, 2013 You are also going to have to escape the data. See mysql_real_escape_string. You need to escape the filename as well. Other things to consider: 1) The mysql_ extension has been depricated. New development should use the improved version: mysqli. 2) Storing the actual image in a database is generally not very beneficial. Quote Link to comment 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.