Spraban9 Posted March 12, 2013 Share Posted March 12, 2013 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."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/275538-im-have-error-inserting-image-data/ Share on other sites More sharing options...
Solution AyKay47 Posted March 12, 2013 Solution Share Posted March 12, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/275538-im-have-error-inserting-image-data/#findComment-1418149 Share on other sites More sharing options...
Barand Posted March 12, 2013 Share Posted March 12, 2013 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: ACTION BIT DATE ENUM NO TEXT TIME TIMESTAMP Quote Link to comment https://forums.phpfreaks.com/topic/275538-im-have-error-inserting-image-data/#findComment-1418179 Share on other sites More sharing options...
Spraban9 Posted March 13, 2013 Author Share Posted March 13, 2013 thank you it is working friends Quote Link to comment https://forums.phpfreaks.com/topic/275538-im-have-error-inserting-image-data/#findComment-1418288 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.