When a user checks the box, it indicates that we wants it deleted. The user can check multiple checkboxes so make it easier on deleting mass items. I can make it so that one checkbox is deleted easily, but more than that, and it does not work.
To submit the form, it goes to another page, which then loops through all of the items in the database, and then looks at the previous page's variables to see if the checkbox is checked, if it is then it is deleted from the table. Below is what I have made, and is what I would like the final code to look like.
Page with checkboxes...
Code: Select all
<?php
ob_start();
include('header.php'); // connect ($conn) is in the header.php file
$sql_pages = "select * from custom_pages";
$rs_pages = mysql_query($sql_pages, $conn);
while($row = mysql_fetch_array($rs_pages)){
$id = $row['id'];
$name = $row['name'];
$address = $row['address'];
$content = $row['content'];
$order = $row['order'];
echo "<tr>";
echo "<td><font size="2">$order</font></td>";
echo "<td><font size="2">$name</font></td>";
echo "<td><font size="2">$address</font></td>";
echo "<td><a href="?area=manage_p&edit=$name"><font size="2">EDIT</font></a></td>";
echo "<td width="72"><input type="checkbox" name="delete$id" value="ON"></td></tr>";
}
echo "</table>";
// send the form
echo "<br><form action="admin_d_p.php?area=$area" method="post"><input type="submit" value="Delete Pages"></form>";
}
?>Code: Select all
<?php
ob_start();
include('header.php'); // connect ($conn) is in the header.php file
$sql= "SELECT * FROM custom_pages";
$rs= mysql_query($sql, $conn);
while($row = mysql_fetch_array($rs)){
$id = $row['id'];
if($delete == "ON"){
$sql = "DELETE FROM custom_pages WHERE id='$id'";
$rs = mysql_query($sql, $conn) or die(mysql_error());
}
}
header("Location:index.php?area=$area");
?>Thanks.
feyd|use
Code: Select all
tags when posting code[/color]