开发者

PHP/AJAX issue inserting to mysql database

I'm having a problem inserting some data to a mysql database. I have used the same method with other features on the site, and this is the only one causing problems. It's meant to input into 3 field in the database (To, From, Message). As you can see it's a very basic messaging system.

I have the data coming into PHP via AJAX. But the problem is within the INSERT. I have messed around with it for over an hour now - no luck! Here is the code to insert:

mysql_query("INSERT INTO messages (To, From, Message) VALUES('$to','$loggedin','$message') ") 
or die(mysql_error());

And here is the SQL syntax error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for t开发者_如何学Che right syntax to use near 'To, From, Message) VALUES('Ryan','Ryan','hhh')' at line 1

I have tried adjusting a lot of things, no luck! :(


"TO" and "FROM" are reserved keywords, it's not wise to use them as column names. You have to escape them with a back-tick "`". Try this:

INSERT INTO messages (`To`, `From`, `Message`)

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜