Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DELETE FROM multiple conditions

I have two conditions in a DELETE MySQL statement. But it does not delete the record.

$sql="DELETE * FROM sportevent.event_registrations WHERE event_registrations.id = '$id' AND event_registration.eventname = $event";

Is there something wrong with my query? It works if I use only one WHERE condition, but I need to use two.

like image 981
SebastianOpperman Avatar asked Oct 18 '11 06:10

SebastianOpperman


2 Answers

I suspect this:

event_registration.eventname = $event

should be

event_registrations.eventname = $event

After all, you've used the plural form in both the "from" clause and the other part of the "where".

Also note that only one of your parameters is quoted - it's not clear to me how you're providing the parameters, but surely you should be consistent.

like image 144
Jon Skeet Avatar answered Oct 12 '22 13:10

Jon Skeet


Try this

$sql="DELETE FROM sportevent event_registrations WHERE event_registrations.id = '$id' AND event_registrations.eventname = $event";
like image 42
Wazy Avatar answered Oct 12 '22 14:10

Wazy