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.

Edited by tahakirmani
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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