Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-25-2013, 10:02 AM   PM User | #1
emekapromise
New Coder

 
Join Date: May 2011
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
emekapromise is an unknown quantity at this point
I have an error in my insert statement

Please can anybody help me with this error? "SQLSTATE[42000]: Syntax error or access violation: 1064 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 'Usage,Quantity ,UnitCost ,Tax,Vat_5,UnitPrice ,Date_Log ,EntryTime,Reorder_Level' at line 1"

Here is my code:

<code>
$con = new PDO($DSN, $USER, $PWD); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO head_inventory(Bar_Code ,Serial_Number ,Item_Name,Product_Name,Product_Model ,Cat_Name ,Item_Desc,Usage,Quantity ,UnitCost ,Tax,Vat_5,UnitPrice ,Date_Log ,EntryTime,Reorder_Level,Vendor,UserName)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
$stmt = $con->prepare($sql); $stmt->execute(array('" .$Bar_Code. "','".$Serial_Number."','".$Item_Name."','".$Product_Name."','".$Product_Model."','".$Cat_Name."','" .$Item_Desc."','".$Usage."','".$Quantity."','".$UnitCost."','".$Tax."','".$Vat_5."','".$UnitPrice."' ,'".$Date_Log."','".$EntryTime."','".$Reorder_Level."','".$Vendor."','".$UserName."'));
</code>
emekapromise is offline   Reply With Quote
Old 02-25-2013, 02:01 PM   PM User | #2
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 624
Thanks: 16
Thanked 70 Times in 70 Posts
Arcticwarrio is on a distinguished road
try backsticks ` ` around the column names, (the key to the left of 1 on a british keyboard)
PHP Code:
$sql "INSERT INTO head_inventory(`Bar_Code` ,`Serial_Number` ,`Item_Name` ,`Product_Name` ,`Product_Model` ,`Cat_Name` ,`Item_Desc`,`Usage`,`Quantity` ,`UnitCost` ,`Tax` ,`Vat_5` ,`UnitPrice` ,`Date_Log ` ,`EntryTime` ,`Reorder_Level` ,`Vendor` ,`UserName`)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"

__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.
Arcticwarrio is offline   Reply With Quote
Old 02-25-2013, 02:02 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Yep, in particular the USAGE is a reserved word. That must be backticked in order to use it as a field identifier.
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Old 02-25-2013, 02:07 PM   PM User | #4
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 624
Thanks: 16
Thanked 70 Times in 70 Posts
Arcticwarrio is on a distinguished road
also to prevent any errors of this type you might like to read this:

http://en.wikipedia.org/wiki/Hungarian_notation


ie prefix tables with TBL_ eg TBL_head_inventory
and fields with FLD eg FLD_Bar_Code or FLD_Usage
__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.

Last edited by Arcticwarrio; 02-25-2013 at 02:09 PM..
Arcticwarrio is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:41 PM.


Advertisement
Log in to turn off these ads.