question about code

Ive been stuck on this code for too long. Ive compared it to other snippets of code that do the exact same thing for different tables and I can’t figure out why I keep getting a snytax error. Please help.

[php]
$query=“INSERT INTO contactus(name, from, subject, datetime, ipaddress, browser, message)
VALUES(’$name’, ‘$from’, ‘$subject’, ‘$datetime’, ‘$ipaddress’, ‘$browser’, ‘$message’)”;
$result=mysql_query($query) OR die(mysql_error ()); return true;
[/php]

Whats the error message?

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, datetime, ipaddress, browser, message) VALUES(‘From’, ‘email@yahoo’ at line 1

Try
[php]$query=“INSERT INTO contactus(name, from, subject, datetime, ipaddress, browser, message) VALUES(’$name’, ‘$from’, ‘$subject’, ‘$datetime’, ‘$ipaddress’, ‘$browser’, ‘$message’)”;
$result=mysql_query($query) OR die(mysql_error ());
return true;[/php]

Fixed it right up. Thank you so much. I thought I had tried everything. Why would it work on one of my pages, but not another?

Just one of those things i guess. The only reason i suggested it was because we just had a similar question in another thread and what i did here fixed it for that guy.

“FROM” is a reserved word in MySQL so you must use backticks on reserved words (it’s best to not use them at all)

See: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Great info thanks m@tt

Sponsor our Newsletter | Privacy Policy | Terms of Service