Jump to content

[SOLVED] Trying to Delete from two MYSQL tables in php script


rahish

Recommended Posts

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>";  
}
  
?>

 

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

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>";  
}
  
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.