TheStalker Posted November 27, 2008 Share Posted November 27, 2008 Hi i am trying to insert data into a MySql database and keep getting the following error: Error: 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 'from, subject, message, date, time, sentOrReceived) VALUES (0, '12', '2', 'hello' at line 1 i have the follwing set up in my database messageID -int(11) No auto_increment from- varchar(100) subject -varchar(250) message -varchar(1000) date- date time- time sentOrReceived- varchar(7) Here is the SQL code i am using: $time = date("H:i:s",time()); $date = date("d/m/Y"); $messageID = mysql_insert_id(); $sql = "INSERT INTO messaging (messageID, from, subject, message, date, time, sentOrReceived) VALUES (".$messageID.", '".$_POST["from"]."', '".$_POST["subject"]."', '".$_POST["message"]."', ".$date.", ".$time.", ".sent.")"; Link to comment https://forums.phpfreaks.com/topic/134543-solved-simple-insert-problem-i-think/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 27, 2008 Share Posted November 27, 2008 Reserved keywords should not be used as table or column names - http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Link to comment https://forums.phpfreaks.com/topic/134543-solved-simple-insert-problem-i-think/#findComment-700535 Share on other sites More sharing options...
TheStalker Posted November 27, 2008 Author Share Posted November 27, 2008 does that mean i cant use time and date? in my table? i dont really understand? Link to comment https://forums.phpfreaks.com/topic/134543-solved-simple-insert-problem-i-think/#findComment-700539 Share on other sites More sharing options...
Mchl Posted November 27, 2008 Share Posted November 27, 2008 You should not use them as names, and if you do, you have to enclose them in `` Oh, and 'from' is on the list as well I believe Link to comment https://forums.phpfreaks.com/topic/134543-solved-simple-insert-problem-i-think/#findComment-700547 Share on other sites More sharing options...
TheStalker Posted November 27, 2008 Author Share Posted November 27, 2008 cool cheers guys guess that makes sense Also had to change '".$date."', '".$time."', 'sent' didnt have the right quotes Link to comment https://forums.phpfreaks.com/topic/134543-solved-simple-insert-problem-i-think/#findComment-700565 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.