Click to See Complete Forum and Search --> : Can't find the problem in DELETE query


renevanh
06-12-2008, 02:38 PM
I have a database with some data in it.
Now I need to delete a certain row from the database, which I'm trying to do with the following query:


DELETE FROM tbl_cart, tbl_users WHERE tbl_users.username = 'renevanh' AND tbl_cart.KlantID = tbl_users.id AND tbl_cart.product= 'test' LIMIT 1


When I excute this query (MySQL database using PHPmyAdmin), I get an error:

#1064 - 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 tbl_users.username = 'renevanh' AND tbl_cart.KlantID = tbl_users.id AND tb' at line 1

I tried a lot of things, but I can't find the problem.
When I try the same WHERE clause with a SELECT query, it works just fine.

Does anyone see the problem here?

legendx
06-12-2008, 02:43 PM
Does it work if you split it into two queries, one for each table?

renevanh
06-12-2008, 02:46 PM
The point is I'm only removing ONE row from tbl_cart, but I need tbl_users to check for the user and it's ID (got to have the right row... ;) ).

legendx
06-12-2008, 05:15 PM
Try this:


DELETE FROM tbl_cart
WHERE tbl_cart.KlantID IN (SELECT id FROM tbl_users WHERE username = 'renevanh' LIMIT 1) AND tbl_cart.product = 'test'

renevanh
06-17-2008, 05:13 PM
Sorry for the late reply, but it's working in PHPmyAdmin.
Using it with the variables in PHP won't work yet... I guess I make a mistake.

{EDIT}
It was me indeed, stupid space within the page request made the product invalid
{/EDIT}