Jump to content

im have error inserting image data


Spraban9

Recommended Posts

hi friends

i get this error to insert data

"Database query failed: 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 'add,city, date, image) VALUES ('car for sale','mp','car for sale', '0115478956',' at line 1".

 <?php
// May 25, 2010
		 
 include("include/connection.php");
   
if (isset($_FILES['file']) && $_FILES['file']['size'] > 0) { 
        // Temporary file name stored on the server
        
		$title = $_POST['title'];
		$catergory = $_POST['catergory'];
		$des = $_POST['des'];
		$phone=$_POST['phone'];
		$add = $_POST['add'];                                
		$city = $_POST['city'];
		$currentDate = date("F j, Y");
		$tmpName  = $_FILES['file']['tmp_name'];  
        // Read the file 
        $fp      = fopen($tmpName, 'r');
        $data = fread($fp, filesize($tmpName));
        $data = addslashes($data);
        fclose($fp);
		
        $result = mysql_query("INSERT INTO upload  (title, catergory, des, phone,add,city, date, image) VALUES
		 ('$title','$catergory','$des', '$phone','$add','$city','$currentDate','$file')",$conn);
        if(!$result)
        {
            die("Database query failed: ". mysql_error());
        }
        // Print results

        print "Thank you, your file has been uploaded.";
}
  

?>

 

Link to comment
https://forums.phpfreaks.com/topic/275538-im-have-error-inserting-image-data/
Share on other sites

Both add and date are MYSQL reserved words.

To use them in a query you must wrap them in backtics ( ` ).

However, it is encouraged that you change the field names to avoid future errors.

 

For your information: MYSQL Reserved Words

DATE you can get get away with but I'd advise avoiding it and always qualifying it, such as "date_added" or "invoice_date" etc

 

 

MySQL permits some keywords to be used as unquoted identifiers because many people previously used them. Examples are those in the following list:

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.