...

View Full Version : error with sql code



mithereal
03-19-2010, 10:37 AM
i am getting an error when i try to make this sql code
i cant seem to figure out how to solve
[CODE]
foreach($items as $value)
{
echo $value['id']; //this works

$query = "INSERT INTO products (products_id, Id,products_price, products_quantity, products_weight,products_length,products_width,products_height,products_image, vendors_id,products_status,products_date_added)Values ('NULL', $value['id'], $value['price'], $value['quantity'], $value['weight'], $value['length'], $value['width'], $value['height'], $valu['thumbpicurl'], $value['vendor'], '1', 'NULL') ";
}
[CODE]
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

abduraooft
03-19-2010, 10:47 AM
$query = "INSERT INTO products (products_id, Id,products_price, products_quantity,
products_weight,products_length,products_width,products_height,products_image,
vendors_id,products_status,products_date_added)Values ('NULL', {$value['id']}, {$value['price']},
{$value['quantity']}, {$value['weight']}, {$value['length']}, {$value['width']}, {$value['height']},
{$valu['thumbpicurl']}, {$value['vendor']}, '1', 'NULL') ";

SKDevelopment
03-19-2010, 11:28 AM
Does not concern the current problem so just in case: If you are inserting NULL, not string 'NULL', please do not surround it with single quotes. With your query you are inserting strings "NULL" into the DB, not NULL values.

Also please notice that (unless you have not shown this code) all string values must be escaped with mysql_real_escape_string() (http://php.net/mysql_real_escape_string) (I have supposed you are using MySQL) to protect it against SQL injection attacks. Integer and floating point values must be cast explicitly to the corresponding types with intval() (http://php.net/intval) or floatval() (http://php.net/floatval) correspondingly.

And if you have strings, please surround them with single quotes. E.g. {$value['thumbpicurl']} would most probably be a string. If yes, it should be
'{$value['thumbpicurl']}'
instead.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum