2013-07-03 133 views
0

如何在PHP/MySQL中修復此行?服務器返回錯誤嘗試插入幾個值時出現PHP/MySQL語法錯誤

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 ''id', 'title', 'yes', 'no') VALUES (2,test, 0, 0)' at line 1 

爲線

mysql_query("INSERT INTO things('id', 'title', 'yes', 'no') VALUES ($counter,$thing, 0, 0);", $con); 

回答

2
"INSERT INTO things (`id`, `title`, `yes`, `no`) VALUES ($counter,$thing, 0, 0);" 

使用蜱,而不是單引號。另外,你並沒有在那裏引用你的字符串。你應該做適當的消毒。

您應該切換到PDO或mysqli。 mysql_函數已被棄用。

+0

謝謝,這似乎是解決這個問題的報價。但是現在它說''字段列表'中的未知列'testtest',其中testtest是$ thing。 –

+0

沒錯,因爲你不會引用你的字符串。 ($ counter,'$ thing',0,0)在技術上可行,但你應該通過內置的mysqli或者PDO函數來做適當的消毒處理。任何兩個教程將告訴你如何做到這一點 –

+0

我會研究它。謝謝! –

0

您需要大約$計數器和$事情

mysql_query("INSERT INTO things('id', 'title', 'yes', 'no') 
VALUES ('$counter','$thing', 0, 0);", $con); 
相關問題