问题是记录没有在两个表中同时删除.i选择删除链接时获得成功消息。但是从库存表中删除但不在类别表中删除。 从库存中删除后,再次删除记录 然后从类别表中记录删除
1)deletecategoryselect.php
<?php
session_start();
//check if user is logged in,
if(!isset($_SESSION['admin']))
{
header("Location:index.php?page=admin");
}
?>
<h1>Delete Category</h1>
<?php $delcat_sql="SELECT * FROM category"; // get data
$delcat_query=mysqli_query($dbconnect, $delcat_sql);
$delcat_rs=mysqli_fetch_assoc($delcat_query);
do
{ ?>
<p><a href="index.php?page=deletecategoryconfirm&categoryID=<?php echo
$delcat_rs['categoryID']; ?>"><?php echo $delcat_rs['name']; ?></a></p>
<?php
} while ($delcat_rs=mysqli_fetch_assoc($delcat_query));
?>
2)deletecategoryconfirm.php
<?php
session_start();
//check if user is logged in,
if(!isset($_SESSION['admin']))
{
header("Location:index.php?page=admin");
}
?>
<h1>Confirm Category to Delete</h1>
<?php
$delcat_sql="SELECT * FROM category WHERE categoryID=".$_GET['categoryID'];
$delcat_query=mysqli_query($dbconnect, $delcat_sql);
$delcat_rs=mysqli_fetch_assoc($delcat_query);
// check if there are any stock items in this category
$check_sql="SELECT * FROM stock WHERE categoryID=".$_GET['categoryID'];
$check_query=mysqli_query($dbconnect, $check_sql);
$count=mysqli_num_rows($check_query);
?>
<p>
<?php
if($count>0)
{
echo "Warning!!! <br> There are ".$count." stock item(s) in this
category. If you delete the category they will also be delete from
database";
}
?>
</p>
<p><?php echo "Do you really wish to delete : ".$delcat_rs['name']."?"; ?>
</p>
<p><a href="index.php?page=deletecategory&categoryID=<?php echo
$_GET['categoryID']; ?>"> Yes, delete it!</a> |
<a href="index.php?page=deletecategoryselect"> No, go back</a> |
<a href="index.php?page=admin"> Back to admin panel</a>
</p>
3)deletecategory.php
<?php
session_start();
//check if user is logged in,
if(!isset($_SESSION['admin']))
{
header("Location:index.php?page=admin");
}
$delcat_sql="DELETE FROM category WHERE
categoryID=".$_GET['categoryID'];
$delcat_query=mysqli_query($dbconnect, $delcat_sql);
$delstock_sql="DELETE FROM stock WHERE categoryID=".$_GET['categoryID'];
$delstock_query=mysqli_query($dbconnect, $delstock_sql);
?>
<h1>Category Deleted</h1>
<p>Category has successfully been deleted</p>
<p><a href="index.php?page=admin">Return to admin panel</a> | <a
href="index.php?page=deletecategoryselect" >Return to Delete category
select</a></p>