Jump to content

Mysql Session Error.


tahakirmani

Recommended Posts

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

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

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.