Jump to content

Very simple error with mysql_query syntax !


Samza

Recommended Posts

Hey,

 

I am getting this error;

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 '' at line 1

 

and the mysql_query is;

$sql = mysql_query("INSERT INTO shopping_cart (cart_identifier, product_id, product_title, product_qty, product_price, sdate) VALUES ('". mysql_real_escape_string($_SESSION['cid']) . "', '$product_id', '{$products['product_title']}', '$product_qty', '{$products[product_price]}', '$sdate'") or die (mysql_error());

I have exhausted every optional my knowledge can devise! :shrug:

 

Thanks for your help,

 

Sam

Whenever you have query problems like this... echo out the query for debugging...

 

I'm willing to bet you will see what your problem is. One of the values might be containing a character that is breaking the query.

 

 

echo "INSERT INTO shopping_cart (cart_identifier, product_id, product_title, product_qty, product_price, sdate) VALUES ('". mysql_real_escape_string($_SESSION['cid']) . "', '$product_id', '{$products['product_title']}', '$product_qty', '{$products[product_price]}', '$sdate'")";

I echoed it out and I can't see what is wrong, everything seems to be perfect

 

INSERT INTO shopping_cart (cart_identifier, product_id, product_title, product_qty, product_price, sdate) VALUES ('b221125f5badb81dd17ea21e38453328', '1', 'PHP Baseball Hat', '1', '12.95', '2013-05-02 15:26:35'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.