Nexy Posted July 5, 2008 Share Posted July 5, 2008 Why Hello There! I seem to get an SQL syntax error with this code: <?php $pmuser = mysql_real_escape_string(addslashes(htmlentities($_POST['pmuser']))); $subject = mysql_real_escape_string(addslashes(htmlentities($_POST['pmsub']))); $message = mysql_real_escape_string(addslashes(nl2br(htmlentities($_POST['pmmsg'])))); if($_SESSION['user']) { $sql = "INSERT INTO pm_inbox(user, from, subject, date, message, status) VALUES('$pmuser', '".$_SESSION['user']."', '$subject', '".date('m-j-Y')."', '$message', 'Unread')"; $res = mysql_query($sql) OR die(mysql_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, date, message, status) VALUES('Nexy', 'Nexy', 'O.O' at line 1 One thing I noticed is the error doesn't mention 'user' before 'from' and the values after subject don't come up. Any help would be appreciated! Thank You! Link to comment https://forums.phpfreaks.com/topic/113337-solved-sql-syntax-error-for-insert/ Share on other sites More sharing options...
AndyB Posted July 5, 2008 Share Posted July 5, 2008 http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html from is a MySQL reserved word. You should avoid using it as a table name or field name. Link to comment https://forums.phpfreaks.com/topic/113337-solved-sql-syntax-error-for-insert/#findComment-582294 Share on other sites More sharing options...
Nexy Posted July 5, 2008 Author Share Posted July 5, 2008 Oh, Thank You very much! Link to comment https://forums.phpfreaks.com/topic/113337-solved-sql-syntax-error-for-insert/#findComment-582301 Share on other sites More sharing options...
Nexy Posted July 5, 2008 Author Share Posted July 5, 2008 I ran into another problem. :'( <?php if($_SESSION['user']) { $sql = "INSERT INTO pm_inbox(user, sender, subject, date, message, status) VALUES('$pmuser', '".$_SESSION['user']."', '$subject', '".date('m-j-Y')."', '$message', 'Unread')"; $res = mysql_query($sql) OR die(mysql_error()); $sqld = "INSERT INTO pm_draft(user, sender, subject, date, message) VALUES('$pmuser', '".$_SESSION['user']."', '$subject', '".date('m-j-Y')."', '$message', 'Unread')"; $resd = mysql_query($sqld) OR die(mysql_error()); } ?> The 2nd sql statement doesn't work. It inserts fine in the first one to pm_inbox, but it doesn't go into pm_draft. Any ideas? Thank You! Link to comment https://forums.phpfreaks.com/topic/113337-solved-sql-syntax-error-for-insert/#findComment-582317 Share on other sites More sharing options...
otuatail Posted July 5, 2008 Share Posted July 5, 2008 Your second quirey is missing ' status' You have 5 fields but 6 values. This should give error messge columb count does not match. Desmond Link to comment https://forums.phpfreaks.com/topic/113337-solved-sql-syntax-error-for-insert/#findComment-582347 Share on other sites More sharing options...
Nexy Posted July 5, 2008 Author Share Posted July 5, 2008 Oh wow, another stupid mistake D:! Thank You! Link to comment https://forums.phpfreaks.com/topic/113337-solved-sql-syntax-error-for-insert/#findComment-582348 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.