Error using 'where' in mysql query

Hi,

I am using this query:

	
	$sql = "INSERT INTO cart (emailaddress, firstname, lastname, address1, address2) VALUES ('$emailaddress', '$firstname', '$lastname', '$address1', '$address2') where cookieid = '" . GetCartId() . "')";

and 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 ‘where cookieid = ‘3na0c1frfs2uo3gl462ajm0c1’)’ at line 1

I want to add the data provided where cookieid=users cookie. But it says the error above!

Any ideas?

Matt.

:cool:

got it. works like a dream,

Matt.

UPDATE bla SET a=1, b=2, c=3 WHERE something=‘somethingelse’

I have tried this instead:


$sql = "update cart set emailaddress='$emailaddress' where cookieid = '" . GetCartId() . "'";

and it works. But how do I get multiple entries!?!

Your syntax is incorrect. Did you look up how to set multiple values in an update query?

Google “update set sql” and you’ll get lots of examples showing how to fix your update query.

Insert seemed logical to me.

What happens is someone adds something to the basket. And when they do it saves their cookie value and product and quantity they have bought.

When they click proceed on the basket page, they then enter their name, telephone, address, etc. This information needs entering in the same row in the MySQL table as the their basket contents and cookie value. That is why I am adding this data where the cookie in the table matches the value in their computer.

I have tried your update idea. It does not work but may be it incorrectly coded:


$sql = "update cart set (emailaddress, firstname, lastname, address1, address2) to ('$emailaddress', '$firstname', '$lastname', '$address1', '$address2') where cookieid = '" . GetCartId() . "'";

What should I use? I believe I need to use WHERE but if i cannot use it with INSERT what can be done!?

Matt.

Also, I noticed you have an excess close bracket after your WHERE clause.

You can’t use WHERE in an INSERT query. What are you trying to achieve?
Did you maybe mean to UPDATE instead of INSERT?