tahakirmani Posted December 19, 2012 Share Posted December 19, 2012 Hi, I am creating a small PHP program where a user enter his username and password, and his profile opens, where he can upload his Pictures. I have written the following code for uploading image, where i am using SESSION variable to INSERT image data in Mysql Table. Its giving me an error message when i am using SESSION variable, if i use normal number in ID field it inserts a record. Kindly check it and help me in pointing out the error. <form acton="users_images.php" method='POST' enctype="multipart/form-data" > FILE: <input type="FILE" name="image"> <input type="submit" value="Upload Image"> </form> <?php include "core.php"; mysql_connect('localhost','root','' ); mysql_select_db('a_database'); $file= $_FILES['image']['tmp_name']; if(!isset($file)) { echo "Please Upload an Image"; }else { $image= mysql_real_escape_string(file_get_contents ($_FILES['image']['tmp_name'])); $image_name= mysql_real_escape_string($_FILES['image']['name']); $image_size= getimagesize($_FILES['image']['tmp_name']); $image_temp_loc= mysql_real_escape_string($_FILES['image']['tmp_name']); $current_id= $_SESSION['user_id']; if ($image_size==FALSE){ echo "Invalid Image"; }else { $query= "INSERT INTO email_images VALUES ('$current_id', '$image', '$image_temp_loc') where `id`=".$_SESSION['user_id']. "" ; //successfull //$query= "INSERT INTO email_images VALUES ('', '$image', '$image_temp_loc')" ; if (!$query_run=mysql_query($query)){ echo "Query Unsuccessful ".mysql_error(); } else { echo "successful"; } } } ?> ERROR MESSAGE :- Query UnSuccessful 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 'where `id`=1' at line 1 Thanks, Taha. Link to comment https://forums.phpfreaks.com/topic/272195-mysql-session-error/ Share on other sites More sharing options...
Christian F. Posted December 19, 2012 Share Posted December 19, 2012 If you echo out the generated SQL query, the error should be a lot easier to spot. Link to comment https://forums.phpfreaks.com/topic/272195-mysql-session-error/#findComment-1400429 Share on other sites More sharing options...
tahakirmani Posted December 19, 2012 Author Share Posted December 19, 2012 INSERT INTO email_images VALUES ('1', 'ÿØÿà\0JFIF\0.................................... , 'F:\\xampp\\tmp\\php6DE3.tmp') where `id`=1 *.....its too long text. Link to comment https://forums.phpfreaks.com/topic/272195-mysql-session-error/#findComment-1400436 Share on other sites More sharing options...
Christian F. Posted December 19, 2012 Share Posted December 19, 2012 I just realized you had an INSERT query, which explains the problem. If you check out the MySQL manual for INSERT, you'll see that there is no WHERE clause for it. What you want is probably an UPDATE query, if you want to update an already existing row. Link to comment https://forums.phpfreaks.com/topic/272195-mysql-session-error/#findComment-1400447 Share on other sites More sharing options...
tahakirmani Posted December 19, 2012 Author Share Posted December 19, 2012 Thank You so Much again !!! It is working now Link to comment https://forums.phpfreaks.com/topic/272195-mysql-session-error/#findComment-1400452 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.