473,597 Members | 2,420 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 1806
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
3929
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 this has me stumped. Any help will be much appreciated. Many thanks in advance
0
3515
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
3938
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
3016
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 be to enter any integer into B_TAB.AID regardless of weather that value exists anywhere in the...
10
52541
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
5028
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
3366
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 no protests when built, ran and connected with no
1
4800
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 performance.I tried it with a plain-old loop, but it is still slow. Oracle supports such feature and it...
5
2263
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 appropriate forum because the problems I'm having relate to PHP. Any help appreciated. ...
9
1742
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
7883
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8379
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8254
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5421
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3876
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3917
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2393
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
1492
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.