Delete data in two tables at the same time

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
enna
Forum Newbie
Posts: 8
Joined: Thu Jun 04, 2009 4:54 am

Delete data in two tables at the same time

Post by enna »

hi can someone help me..i need to delete data in two tables at the same time..here is my sql code..it won't work..thank you

$data = $_POST['data'];
mysql_query("DELETE FROM table1 WHERE column='$data'; DELETE FROM table2 WHERE column='$data'")
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Delete data in two tables at the same time

Post by VladSun »

You can't execute more than one query at a time by using standard mysql_* functions.
You have to call mysql_query twice.

Also, you may find http://bg2.php.net/manual/en/mysqli.multi-query.php useful.

And finally - you may find MySQL innoDB TRIGGERS useful too.
http://dev.mysql.com/doc/refman/5.0/en/triggers.html
There are 10 types of people in this world, those who understand binary and those who don't
enna
Forum Newbie
Posts: 8
Joined: Thu Jun 04, 2009 4:54 am

Re: Delete data in two tables at the same time

Post by enna »

VladSun wrote:You can't execute more than one query at a time by using standard mysql_* functions.
You have to call mysql_query twice.

Also, you may find http://bg2.php.net/manual/en/mysqli.multi-query.php useful.

And finally - you may find MySQL innoDB TRIGGERS useful too.
http://dev.mysql.com/doc/refman/5.0/en/triggers.html
thank you..it's working now.. :D
Post Reply