2012-04-10 44 views
2
$query = "INSERT INTO textbooks (uid, title, edition, author, isbn, condition, description, photo) VALUES (9, 'q', 'a', 'b', 'c', 'd', 'e', '$extension')"; 

$result = mysql_query($query) or die('Could not connect: ' . mysql_error()); 

Could not connect: 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 'condition, description, photo) VALUES (9, 'q', 'a', 'b', 'c', 'd', 'e', '.jpg')' at line 1 

我一直在收到一個MySQL語法錯誤,但我不能爲我的生活弄清楚什麼是錯的。我放置了隨機變量,字符串和int只是爲了測試,但它不工作。PHP中的MySQL語法錯誤

  1. 標題,版本,作者,ISBN條件,描述,照片都是VARCHAR處理
  2. UID是一個i​​nt
  3. 介紹文字
+0

你試過用'而不是單引號? – mc10 2012-04-10 05:10:09

+0

'CONDITION'是[保留關鍵字](http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html)。 – Wiseguy 2012-04-10 05:11:10

回答

5

condition在MySQL中保留字。使用`condition`

1

試試這個:

$query = "INSERT INTO `textbooks` (`uid`, `title`, `edition`, `author`, `isbn`, `condition`, `description`, `photo`) VALUES (9, 'q', 'a', 'b', 'c', 'd', 'e', '$extension')"; 
0

短語「condition」是MySQL中的一個保留字。只需將其更改爲其他內容,或使用「condition」,則應該很好。

在這裏看到更多的話:http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html

此外,有沒有你爲什麼手動指定UID一個特別的原因?自動遞增適用於大多數應用程序,因此請確保您正確使用它。

+0

我實際上有一個自動遞增的id字段和另一個uid字段。 uid字段用於匹配我在數據庫中的兩個表。 – user1307016 2012-04-10 05:15:01

0

條件是mySql保留關鍵字,因此您可能不會使用此字段名稱,我們可以使用 ,但在查詢中可以使用這樣的condition

0

使用另一個詞代替條件。或使用condition