Jump to content

Delete From Several Tables


son
 Share

Recommended Posts

On click on a button data in db should be either totally removed or all table data other than one deleted. I am having trouble for the right way of running all those queries in one go. I post the code below:

$deleteQuery = "DELETE FROM tab1 WHERE tabID= $tabID;";  $deleteQuery .= "DELETE FROM tab2 WHERE tabID= $tabID;";    if ($_GET['conf'] == '2')   {   $deleteQuery .= "DELETE FROM tab3 WHERE tabID= $tabID;";	  $deleteQuery .= "DELETE FROM tab4 WHERE tabID= $tabID";   }   else   {   $deleteQuery .= "DELETE FROM tab3 WHERE tabID= $tabID";   }if ($deleteResult = mysqli_query ($dbc, $deleteQuery))   {echo "Success"}else{echo "Did not work";}

Where am I going wrong? Son

Link to comment
Share on other sites

Jsg, You mean the PHP developers added protection against doing what Son is trying to do? Or did you mean protection against trying to run consecutive queries right after another at a time?(what scientist suggested)

Edited by Don E
Link to comment
Share on other sites

The first one, you can't send more than one query in a query string to mysql_query, you can only send one query at a time. That's a protection against SQL injection attacks which try to append another query onto the one you're trying to run. It's not helpful for people who protect against SQL attacks themselves, it's similar to magic_quotes in that it tries to protect programmers who don't really understand what they're doing.

Link to comment
Share on other sites

I am with you and will run all queries separately... Just as I always use

if ($deleteResult = mysqli_query ($dbc, $deleteQuery))   {echo "Success"}else{echo "Did not work";}

is there a way to check in one go if they all went fine without causing any issues? Or is this not a good idea? In any case, I like to dispay text to show all went ok (all queries)... Son

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...