The script creates the form that is on the page, but it just seems to miss out the delete queries altogether, could someone possibly check it for me.
Thanks
Kevin
Code: Select all
<?php
if ($_POST['op'] != "delete") {
//haven't seen the form, so show it
$display_block = "<h1>Select a Book</h1>";
//get parts of records
$get_list = "SELECT cat_id, concat_ws(', ', item_name) AS display_name FROM store_items
RIGHT JOIN store_categories ON store_items.cat_id = store_categories.id
WHERE store_categories.id = 1";
$get_list_res = mysql_query($get_list) or die(mysql_error());
if (mysql_num_rows($get_list_res) < 1) {
//no records
$display_block .= "<p><em>Sorry, no records to select!</em></p>";
} else {
//has records, so get results and print in a form
$display_block .= "
<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<p><strong>Select a Record to Delete:</strong></p><br>
<select name=\"sel_id\">
<option value=\"\">-- Select One --</option>";
while ($recs = mysql_fetch_array($get_list_res)) {
$cat_id = $recs[cat_id];
$display_name = stripslashes($recs['display_name']);
$display_block .= "<option value=\"$cat_id\">
$display_name</option>";
}
$display_block .= "
</select>
<input type=\"hidden\" name=\"op\" value=\"delete\">
<p><input type=\"submit\" name=\"submit\" value=\"Delete Selected Entry\"></p>
</form>";
}
} else if ($_POST['op'] == "delete") {
//check for required fields
if ($_POST['sel_id'] == "") {
header("Location: delbook.php");
exit;
}
//issue queries
$del_items = 'DELETE FROM store_items WHERE id = '.$_POST['sel_id'];
mysql_query($del_items) or die(mysql_error());
$del_books = 'DELETE FROM store_books WHERE item_id = '.$_POST['sel_id'];
mysql_query($del_books) or die(mysql_error());
$flush_items = 'FLUSH TABLE `store_items`';
mysql_query($flush_items) or die(mysql_error());
$flush_books = 'FLUSH TABLE `store_books`';
mysql_query($flush_books) or die(mysql_error());
$display_block = "<h1>Record(s) Deleted</h1>
<p>Would you like to
<a href=\"$_SERVER[PHP_SELF]\">delete another</a></p>";
}
?>
<html>
<head>
<title>Delete a Book</title>
</head>
<body>
<?php echo $display_block;?>
</body>
</html>