Reputation: 992
I wrote this code:
mysql_query("INSERT INTO test (user_id, word_id, right) VALUES ('6', '23', '5' )") or die(mysql_error());
But an error message prompts:
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 ('6', '23', '5' )' at line 1
What I did wrong?
Upvotes: 0
Views: 67
Reputation: 79899
right
is a reserved word , escape it like so:
INSERT INTO test (user_id, word_id, `right`) VALUES ('6', '23', '5' )
Note that:1
Use of this extension(mysql_query) is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
mysqli_query() PDO::query()
1:quoted from PHP Manual: mysql_query
Upvotes: 4
Reputation: 631
INSERT INTO `test` (`user_id`, `word_id`, `right`) VALUES ('6', '23', '5' )
Upvotes: 0
Reputation: 57312
right
is reserved key word 9.3. Reserved Words
when we use reserved keyword we need to escape them try
mysql_query("INSERT INTO test (user_id, word_id, `right`) VALUES ('6', '23', '5' )") or die(mysql_error());
Upvotes: 2
Reputation: 13465
Try this :::RIGHT
is known keyword, try a backtick
INSERT INTO test (`user_id`, `word_id`, `right`) VALUES ('6', '23', '5' )
Upvotes: 0