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 只是为了测试,但它不起作用。

  1. title, edition, author, isbn, condition, description, photo 都是 varchars
  2. uid 是一个整数
  3. 描述是文字
4

6 回答 6

5

condition is reserved word in mysql. Use `condition`

于 2012-04-10T05:12:50.247 回答
4

condition is a MySQL reserved word.

于 2012-04-10T05:11:12.140 回答
1

Try this :

$query = "INSERT INTO `textbooks` (`uid`, `title`, `edition`, `author`, `isbn`, `condition`, `description`, `photo`) VALUES (9, 'q', 'a', 'b', 'c', 'd', 'e', '$extension')";
于 2012-04-10T05:11:26.320 回答
0

The phrase "condition" is a reserved word in MySQL. Just change that to something else, or use "condition", and you should be good to go.

See here for more of the words: http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html

Also, is there a particular reason why you are specifying the UID manually? Auto incrementing is suitable for the majority of applications, so be sure you are utilizing that properly.

于 2012-04-10T05:12:52.720 回答
0

condition is mySql reserved keyword so you might not use this as field name, we can use but give condition like this in query.

于 2012-04-10T05:15:31.613 回答
0

Use another word instead of condition. Or use condition.

于 2012-04-10T05:17:21.073 回答