MySQL: Select a line from a table, then delete it.
Posted: Sat Sep 06, 2008 8:26 pm
Hi guys! This is my first post here, and believe me, I did my homework.
My dilemma is that I need to provide a website owner with the ability to delete categories from her online store.
This whole store is written in the procedural style, so the main file (admin.php in this case) is set to load the include file named after whatever value is assigned to the variable "content".
So this operation involves 2 files: killcat.inc which presents the list of entries from the "categories" table, and deletecat.inc, which takes the submitted form and runs the query to delete the category.
The problem is that when the form on killcat.inc is submitted, a blank page is returned. In other words, deletecat.inc returns nothing and the query is never run. I scrutinized this for obvious errors all evening last night and came up empty.
What am I missing?
killcat.inc
deletecat.inc
I know you guys are volunteers so I really appreciate your help, and I'll do my best to find and answer other questions on this board!
My dilemma is that I need to provide a website owner with the ability to delete categories from her online store.
This whole store is written in the procedural style, so the main file (admin.php in this case) is set to load the include file named after whatever value is assigned to the variable "content".
So this operation involves 2 files: killcat.inc which presents the list of entries from the "categories" table, and deletecat.inc, which takes the submitted form and runs the query to delete the category.
The problem is that when the form on killcat.inc is submitted, a blank page is returned. In other words, deletecat.inc returns nothing and the query is never run. I scrutinized this for obvious errors all evening last night and came up empty.
What am I missing?
killcat.inc
Code: Select all
<?php
if (!isset($_SESSION['store_admin']))
{
echo "<h2>Sorry, you have not logged into the system</h2>\n";
echo "<a href=\"admin.php\">Please login</a>\n";
} else
{
echo "<h2>Please select a category to remove.</h2>\n";
echo "<p>Please note that this will also delete all products in the category. If you wish to keep the products, please move them into different categories first.</p>\n";
$query="SELECT catid,name from categories";
$result=mysql_query($query);
echo "<form action=\"admin.php\" method=\"post\">\n";
echo "<input name=\"content\" type=\"hidden\" value=\"deletecat\" />\n";
echo "<select name=\"catid\">";
while($row=mysql_fetch_array($result,MYSQL_ASSOC))
{
$catid = $row['catid'];
$name = $row['name'];
echo "<option value=\"$catid\">$name</option>\n";
}
echo "</select>\n";
echo "<input type=\"submit\" name=\"goButton\" value=\"Remove selected category\" />\n";
echo "</form>";
}
?>
Code: Select all
<?php
$delete = $_POST['goButton'];
$catid = $_POST['catid'];
if (isset($_POST['goButton']))
{
$query = "DELETE from categories WHERE catid = $catid";
$result = mysql_query($query);
if ($result)
{
echo "<h2>Category: $catid deleted</h2>\n";
exit;
} else
{
echo "<h2>Problem deleting $prodid</h2>\n";
exit;
}
?>