Jump to content

Very simple error with mysql_query syntax !


Go to solution Solved by akphidelt2007,

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'

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.