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

I've been receiving a MySQL syntax error but I can't for the life of me figure out what's wrong. I placed in random variables, strings, and int just to test but it's not working.

  1. title, edition, author, isbn, condition, description, photo are all varchars
  2. uid is an int
  3. description is text
Ankit Sharma
  • 3,923
  • 2
  • 29
  • 49
user1307016
  • 383
  • 1
  • 8
  • 17

6 Answers6

5

condition is reserved word in mysql. Use `condition`

Milan Halada
  • 1,943
  • 18
  • 28
4

condition is a MySQL reserved word.

codaddict
  • 445,704
  • 82
  • 492
  • 529
1

Try this :

$query = "INSERT INTO `textbooks` (`uid`, `title`, `edition`, `author`, `isbn`, `condition`, `description`, `photo`) VALUES (9, 'q', 'a', 'b', 'c', 'd', 'e', '$extension')";
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
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.

tcole
  • 947
  • 6
  • 14
  • I actually have an auto-incrementing id field and another uid field. The uid field is for matching the 2 tables I have in my database. – user1307016 Apr 10 '12 at 05:15
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.

Nagaraju Badaeni
  • 890
  • 8
  • 14
0

Use another word instead of condition. Or use condition.

Santosh
  • 11
  • 2