473,406 Members | 2,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Insert to table problem

290 100+
What could be the reason for this failure to insert a row ?

Here is my insert code:


Expand|Select|Wrap|Line Numbers
  1. $sql = "INSERT INTO `products` (live,cat_cd,long,user_id,prod_name,prod_desc_sht,prod_desc_lng)
  2. VALUES 
  3. ('$Db_live_cd','$Db_cat_cd','$Db_long_cd','{$_SESSION['expert']}','$Db_prod_name','$Db_prod_desc_sht','$Db_prod_desc_lng')";
  4.  
  5. echo "SQL: $sql";
  6.  
  7. $result = mysql_query($sql) or die("could not execute ADD a PRODUCT.". mysql_error()); 
  8.  
This is my error message:
could not execute ADD a PRODUCT.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 'long,user_id,prod_name,prod_desc_sht,prod_desc_ln g) VALUES ('y','se','y',' at line 1

My table structure is here:

Expand|Select|Wrap|Line Numbers
  1. $sql = "CREATE TABLE `products` (
  2.   `prod_id` int(4) NOT NULL AUTO_INCREMENT,
  3.   `confirm` char(1) NOT NULL default '',
  4.   `live` char(1) NOT NULL default '',
  5.     `type` char(1) NOT NULL default '',
  6.     `cat_cd` char(2) NOT NULL default '',
  7.     `long` char(1) NOT NULL default 'y',
  8.   `user_id` varchar(25) NOT NULL default '',
  9.     `prod_name` varchar(40) NOT NULL default '',
  10.   `prod_pict` varchar(25) NOT NULL default '',
  11.     `prod_desc_sht`  text NOT NULL default '',
  12.     `prod_desc_lng`  text NOT NULL default '',
  13.     `prod_link` varchar(50) NOT NULL default '',
  14.     `valid_fm_date` int(12) default NULL,
  15.   `valid_to_date` int(12) default NULL,
  16.     `vote_count` int(3) default '0',
  17.     `sales_count` int(3) default '0',
  18.      KEY `user_id` (`user_id`),
  19.      KEY `prod_id` (`prod_id`),
  20.      PRIMARY KEY (prod_name)
  21.  
  22. ) ENGINE=MyISAM DEFAULT CHARSET=latin1";
  23.  
I can not see any reason for the failure !!!

Any ideas ?
Jan 27 '09 #1
2 1895
jeddiki
290 100+
Just found out that "long" is a reserved word so I'll change the field name.
Jan 27 '09 #2
Atli
5,058 Expert 4TB
Hi.

You can use reserved keywords as field/table/database names if you enclose them in back-ticks (as you do in the CREATE query).

But avoiding using them (at least by themselves) is still a good idea.
Jan 27 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM,...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
8
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
4
by: Chris Kratz | last post by:
Hello all, We have run into what appears to be a problem with rules and subselects in postgres 7.4.1. We have boiled it down to the following test case. If anyone has any thoughts as to why...
7
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
1
by: veasnamuch | last post by:
I have a problem while I create a trigger to my table. My objective is getting any change made to my table and record it in to another table . My have thousands records before I add new trigger to...
4
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.