Enjoy an ad free experience by logging in. Not a member yet?
Register .
02-25-2013, 10:02 AM
PM User |
#1
New Coder
Join Date: May 2011
Posts: 36
Thanks: 3
Thanked 0 Times in 0 Posts
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>
02-25-2013, 02:01 PM
PM User |
#2
Regular Coder
Join Date: May 2012
Location: UK
Posts: 624
Thanks: 16
Thanked 70 Times in 70 Posts
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.
02-25-2013, 02:02 PM
PM User |
#3
God Emperor
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
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' );
02-25-2013, 02:07 PM
PM User |
#4
Regular Coder
Join Date: May 2012
Location: UK
Posts: 624
Thanks: 16
Thanked 70 Times in 70 Posts
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 ..
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 01:41 PM .
Advertisement
Log in to turn off these ads.