By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,888 Members | 1,588 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,888 IT Pros & Developers. It's quick & easy.

MySQL INSERT problem

P: n/a
I am trying to insert data into the fields id and term of the table
key. id is an auto-incrementing field.

Each of the following forms fails:-

INSERT INTO key (id, term) VALUES (0, 'dog')

INSERT INTO key ('id', 'term') VALUES (0, 'dog')

INSERT INTO 'key' ('id', 'term') VALUES (0, 'dog')

INSERT INTO 'key' (id, term) VALUES (0, 'dog')

mysql_error() returns messages of the following form:-

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 'key (id,
term) VALUES (0, 'dog')' at line 1

What is wrong with the syntax?

Caversham

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Caversham (ac******@yahoo.com) wrote:
: I am trying to insert data into the fields id and term of the table
: key. id is an auto-incrementing field.

: Each of the following forms fails:-

: INSERT INTO key (id, term) VALUES (0, 'dog')

: INSERT INTO key ('id', 'term') VALUES (0, 'dog')

: INSERT INTO 'key' ('id', 'term') VALUES (0, 'dog')

: INSERT INTO 'key' (id, term) VALUES (0, 'dog')

: mysql_error() returns messages of the following form:-

: 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 'key (id,
: term) VALUES (0, 'dog')' at line 1

: What is wrong with the syntax?

Guessing, but is key a keyword? You might need to use a different name
for the table.
--

This space not for rent.
Jul 17 '05 #2

P: n/a
Malcolm Dew-Jones wrote:
Caversham (ac******@yahoo.com) wrote:
: I am trying to insert data into the fields id and term of the table
: key. id is an auto-incrementing field.

: Each of the following forms fails:-

: INSERT INTO key (id, term) VALUES (0, 'dog')

: INSERT INTO key ('id', 'term') VALUES (0, 'dog')

: INSERT INTO 'key' ('id', 'term') VALUES (0, 'dog')

: INSERT INTO 'key' (id, term) VALUES (0, 'dog')

: mysql_error() returns messages of the following form:-

: 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 'key (id,
: term) VALUES (0, 'dog')' at line 1

: What is wrong with the syntax?

Guessing, but is key a keyword? You might need to use a different name
for the table.


If this is so, he should be able to use backticks ' ` ' to do the job:

INSERT INTO `key` (id, term) VALUES (0, 'dog')

Cheers,
Nicholas Sherlock
Jul 17 '05 #3

P: n/a


Caversham wrote:
I am trying to insert data into the fields id and term of the table
key. id is an auto-incrementing field.

Each of the following forms fails:-

INSERT INTO key (id, term) VALUES (0, 'dog')

INSERT INTO key ('id', 'term') VALUES (0, 'dog')

INSERT INTO 'key' ('id', 'term') VALUES (0, 'dog')

INSERT INTO 'key' (id, term) VALUES (0, 'dog')

mysql_error() returns messages of the following form:-

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 'key (id,
term) VALUES (0, 'dog')' at line 1


Use the following syntax:

insert into `key` set term='dog';

If you don't specify the auto increment field, it will "do the right
thing", autoincrement. Any other fields you don't specify will take
their default values.

Ken

Jul 17 '05 #4

P: n/a

On 17-Jun-2005, "Caversham" <ac******@yahoo.com> wrote:
INSERT INTO key (id, term) VALUES (0, 'dog')

INSERT INTO key ('id', 'term') VALUES (0, 'dog')

INSERT INTO 'key' ('id', 'term') VALUES (0, 'dog')

INSERT INTO 'key' (id, term) VALUES (0, 'dog')

mysql_error() returns messages of the following form:-

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 'key (id,
term) VALUES (0, 'dog')' at line 1

What is wrong with the syntax?


"key" is a mysql keyword and needs to be enclosed in backticks: `key`

http://dev.mysql.com/doc/mysql/en/reserved-words.html

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.