473,566 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MySQL INSERT problem

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
4 1804
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
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


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

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*********@wil lglen.net (it's reserved for spammers)
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3927
by: Simon | last post by:
Hi, I am having a little problem with my PHP - MySQl code, I have two tables (shown below) and I am trying populate a template page with data from both. <disclaimer>Now I would like to say my skills, especially with MySQL are rudimentary</disclaimer> However my code (link below) fails, the nested database call does not return any data and...
0
3513
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary form for a number of platforms from our download pages at http://www.mysql.com/downloads/ and mirror sites.
0
3931
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest version of this document can be found at: http://prdownloads.sourceforge.net/souptonuts/README_mysql.txt?download
1
3014
by: Saqib Ali | last post by:
I have created 2 tables in my MySQL database. A_TAB and B_TAB. They have auto-incrementing integer primary keys respectively named A_ID & B_ID. When I created B_TAB, I declared a field named A_ID which references A_TAB.AID. I insert valid data into both tables. However, the foreign key constraint is NOT being enforced. The database allows...
10
52482
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable string or NULL. Becaus i have a if statement: if .... cursor.execute(".................insert NULL ..............") if ....
34
5006
by: Karam Chand | last post by:
Hello I have been working with Access and MySQL for pretty long time. Very simple and able to perform their jobs. I dont need to start a flame anymore :) I have to work with PGSQL for my companies current project. I have been able to setup postgresql in my rh box and
1
3362
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer uses his own php shopping cart to receive customer orders. The configuration was done via cPanel with no external modifications - which produced...
1
4799
by: The|Godfather | last post by:
Hello, I have a "slight" problem with the mySQL C API. I want to bind vectors for output/input prepared statements. However, the C API does NOT support such data binding. Is there ANY other way to do a bulk-INSERT/DELETE/UPDATE or bulk-SELECT in mySQL C API? I mean, one can do it with a loop, but obiously the goal is to have a higher...
5
2262
by: strawberry | last post by:
In the function below, I'd like to extend the scope of the $table variable such that, once assigned it would become available to other parts of the function. I thought 'global $table;' would solve this but it's clear that I'm misunderstanding $variable persistence. I posted a similar enquiry over at alt.php.mysql, but I guess this is a more...
9
1740
by: KDawg44 | last post by:
Hi, I have PHP function that adds a record to the database. The table has an ID that is AUTO_INCREMENT. Is there anyway to get that ID back when I do any kind of insert? That ID is a foreign key that I need to do an insert on afterwards. Thanks. Kevin
0
7666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.