2

It keep getting this SQL error, but I am very certain there are no errors in the query. I have been staring at it too long. Is there something else that might cause this?

INSERT INTO game_data (clue, image, answer, wrong, right) VALUES ('asdf',         'asdf', 'asdf', 'assdf', 'asdf')

Invalid Query: 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 'right) VALUES ('asdf', 'asdf', 'asdf', 'assdf', 'asdf')' at line 1

I have run other queries with this exact code, just swapping out the variables, and it works.

and for good measure, there is the php that generates this:

$sql = "INSERT INTO game_data (clue, image, answer, wrong, right) VALUES
    ('" . $clue . "', '" . $image . "', '" . $answer . "', '" . $wrong . "', '" . $right . "')";
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331

2 Answers2

11

right is a reserved keyword in MYSQL. You need to escape it using backticks like this:

INSERT INTO game_data (`clue`, `image`, `answer`, `wrong`, `right`) VALUES

Note: Try to avoid naming your columns as reserved keyword names in future.

dnoeth
  • 59,503
  • 4
  • 39
  • 56
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
0

The name 'right' is a MySQL reserved keyword. I dont know how can you create 'right' column.

hai tran
  • 21
  • 1