rahish Posted May 21, 2009 Share Posted May 21, 2009 I am creating a very simple cms system and have a delete statement which is supposed to delete an item from a menu table and a page table which (has an identical id) when an admin user deletes the page There is an if statement that sends and integer "1" if the admin user has clicked the html checkbox on a form to ask for the page to be deleted from the menu as well as the page itself. I can't work out the syntax of the mysql statement to do this I am not sure if this is the right forum for this question. But here is the code I am using <?php include('../dbconnection.php'); $submit=$_GET['submit']; $id=$_GET['id']; $menu=$_GET['menu']; if ( $menu=='1' ) { $query=mysql_query("DELETE FROM menu, pages WHERE menu.id AND pages.page_id=$id") or die ("Couldn't execute query."); //$query = mysql_query("DELETE FROM menu WHERE id=$id") or die (mysql_error()); echo "You have now deleted entry $id from the database and entry $id from the menu<br />"; echo " <a href='posts.php?id=$id'>Click here to go back</a>"; } else { $query=mysql_query("DELETE FROM pages WHERE page_id=$id") or die ("Couldn't execute query."); echo "You have now deleted entry $id from the database<br />"; echo " <a href='posts.php?id=$id'>Click here to go back</a>"; } ?> Quote Link to comment Share on other sites More sharing options...
madspof Posted May 21, 2009 Share Posted May 21, 2009 erm try this not sure about the syntax of the mysql <?php include('../dbconnection.php'); $submit=$_GET['submit']; $id=$_GET['id']; $menu=$_GET['menu']; if ( $menu=='1' ) { mysql_query("DELETE FROM menu, pages WHERE menu.id AND pages.page_id= '$id'") or die ("Couldn't execute query."); //$query = mysql_query("DELETE FROM menu WHERE id=$id") or die (mysql_error()); echo "You have now deleted entry $id from the database and entry $id from the menu<br />"; echo " <a href='posts.php?id=$id'>Click here to go back</a>"; } else { mysql_query("DELETE FROM pages WHERE page_id= '$id'") or die ("Couldn't execute query."); echo "You have now deleted entry $id from the database<br />"; echo " <a href='posts.php?id=$id'>Click here to go back</a>"; } ?> Edited If that does not work you could just make two individual mysql query's that would be easy to do Quote Link to comment Share on other sites More sharing options...
waynewex Posted May 21, 2009 Share Posted May 21, 2009 I'm not sure if you can merge two delete queries into one. I think that the only way you can do it is if you perform two separate delete queries. Quote Link to comment Share on other sites More sharing options...
rahish Posted May 21, 2009 Author Share Posted May 21, 2009 Thanks I tried both but I am still getting a can't execute query error. This is what I am now using <?php include('../dbconnection.php'); $submit=$_GET['submit']; $id=$_GET['id']; $menu=$_GET['menu']; if ( $menu=='1' ) { $query=mysql_query("DELETE FROM menu WHERE id = '$id'") or die ("Couldn't execute query."); $query2=mysql_query("DELETE FROM pages WHERE pages_id = '$id'") or die ("Couldn't execute query."); echo "You have now deleted entry $id from the database and entry $id from the menu<br />"; echo " <a href='posts.php?id=$id'>Click here to go back</a>"; } else { $query=mysql_query("DELETE FROM pages WHERE page_id=$id") or die ("Couldn't execute query."); echo "You have now deleted entry $id from the database<br />"; echo " <a href='posts.php?id=$id'>Click here to go back</a>"; } ?> Quote Link to comment Share on other sites More sharing options...
madspof Posted May 21, 2009 Share Posted May 21, 2009 try this <?php include('../dbconnection.php'); $submit=$_GET['submit']; $id=$_GET['id']; $menu=$_GET['menu']; if ( $menu=='1' ) { mysql_query("DELETE FROM menu WHERE id = '$id'") or die(mysql_error()); mysql_query("DELETE FROM pages WHERE pages_id = '$id'") or die(mysql_error()); echo "You have now deleted entry $id from the database and entry $id from the menu<br />"; echo " <a href='posts.php?id=$id'>Click here to go back</a>"; } else { mysql_query("DELETE FROM pages WHERE page_id = '$id'") or die(mysql_error()); echo "You have now deleted entry $id from the database<br />"; echo " <a href='posts.php?id=$id'>Click here to go back</a>"; } ?> this will give you some error reporting Quote Link to comment Share on other sites More sharing options...
rahish Posted May 21, 2009 Author Share Posted May 21, 2009 Thanks I had pages_id but the table field was page_id Bit of a schoolboy error there. Thanks for sorting it out. The mysql_error function is really useful, will try that in the future. Quote Link to comment Share on other sites More sharing options...
madspof Posted May 21, 2009 Share Posted May 21, 2009 Its ok mark as solved please Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.