2012-06-20 38 views
1

我正在使用我的網站上的用戶之間的私人消息系統。這裏是我的查詢:無法找出mySQL語法錯誤的來源

$query = "INSERT INTO messages (to, `from`, message) VALUES ('{$user}', '{$username}', '{$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 'to, `from`, message) VALUES ('Cheezey', 'Cheezey', 'Enter your message here')' at line 1 

我有一種揮之不去的感覺,這是我的一個非常愚蠢的錯誤,但我似乎無法弄清楚。

回答

3

這是因爲to是MySQL中的reserved word,你必須把'它周圍,像這樣:

INSERT INTO(`to`, ...). 
+0

謝謝,我不知道它是。當SO會讓我接受你的回答。 – Cheezey