2011-08-23 38 views
1

這是PHP代碼:MySQL的「插入」 SQL語法錯誤問題

$stringquery = "INSERT INTO sikurim(name, title, desc, category, subcategory) 

VALUES ('$contact', '$heading','$comments', '$catF', '$catS') "; 

mysql_query($stringquery) or die(mysql_error()); 

,我得到的錯誤:

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 'desc, category, subcategory) VALUES ('jhjh', ' fffff','fffff', '2', '4')' at line 1

我找不到什麼是錯的代碼,可以有人幫忙?

回答

8

DESCreserved MySQL keyword。你需要把它放在反引號:

$stringquery = "INSERT INTO sikurim(name, title, `desc`, category, subcategory) VALUES ('$contact', '$heading','$comments', '$catF', '$catS')"; 
+0

是的,但最好的肯定是改變列的名稱。 –

+1

,並且請確保您將適當的衛生設施應用於您的變量,如果您將它們插入到您的查詢中! – knittl

+0

現在工作,謝謝:) – Tom