By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

Going absolutely crazy...

P: 1
Please help Can't take it anymore..I am new at this in school have assignment to insert info into database.

Error: INSERT INTO products( Product ID, Product Name, Description, Cost, Markup Percent, Refrigeration Needed, Brand, Year Introduced ) VALUES ('P0026', 'teabags', '24/case', '18', '50.00%','1' ,'Discount' ,'2008')

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 'ID, Product Name, Description, Cost, Markup Percent, Refrigeration Needed, Brand' at line 1
Code as follows:
if (isset ($_POST['submit']))
{
$id=$_POST['pid'];
$name=$_POST['pname'];
$desc=$_POST['pdesc'];
$cost=intval($_POST['pcost']);
$markup=$_POST['pmarkup'];
$fridge=($_POST['pfridge']== 'true') ? true:false;
$brand=$_POST['pbrand'];
$year=$_POST['pyear'];

$sql1="INSERT INTO products( Product ID, Product Name, Description, Cost, Markup Percent, Refrigeration Needed, Brand, Year Introduced ) VALUES ('{$id}', '{$name}', '{$desc}', '{$cost}', '{$markup}','{$fridge}' ,'{$brand}' ,'{$year}')";


$db->query($sql1);
}
Mar 14 '12 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
You should only warp the value in single quotes if the column is a text type. Numeric types should not have their values wrapped in quotes.
Mar 14 '12 #2

Post your reply

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