Andrew R Posted January 25, 2007 Share Posted January 25, 2007 HiAnybody have any idea why I'm getting a SQL syntax error on this script SQL query?[code]mysql_query("INSERT INTO messages (to, subject) VALUES ('$to', '$subject')") or die (mysql_error());[/code]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 'to, subject) VALUES ('Andrew', '456456',)' at line 1Cheers Quote Link to comment https://forums.phpfreaks.com/topic/35681-sql-syntax-error/ Share on other sites More sharing options...
suzzane2020 Posted January 25, 2007 Share Posted January 25, 2007 try takin the space out betweenmessages and (to, subject) mysql_query("INSERT INTO messages(to, subject) VALUES ('$to', '$subject')") or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/35681-sql-syntax-error/#findComment-169036 Share on other sites More sharing options...
HuggieBear Posted January 25, 2007 Share Posted January 25, 2007 You could try quoting the table names with back ticks (`) as [b]to[/b] is a [url=http://dev.mysql.com/doc/refman/4.1/en/reserved-words.html]reserved word[/url]. :D[code]<?php$sql = "INSERT INTO messages (`to`, `subject`) VALUES ('$to', '$subject')";mysql_query($sql) or die ("Unable to run $sql: " . mysql_error());?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/35681-sql-syntax-error/#findComment-169039 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.