bucket
08-24-2009, 11:41 PM
Hello I am working on a script to delete a member from an admin area, basicly a checkbox and a delete button so I can delete multiple at a time.
Here is the Php that shows all the members:
You will see a checkbox for delete.
<?php
require("inc/config.php");
$result = mysql_query("SELECT * FROM persons");
while($row = mysql_fetch_array($result))
{
echo "First Name: " . $row['FirstName'] . "";
echo "<br>";
echo "Last Name: " . $row['LastName'] . "";
echo "<br>";
echo "<a target=frame2 href='" ."profile.php?user1=". $row['FirstName'] ."'>Profile</a>";
echo "<br>";
echo "Date: " . $row['AddedDate'] . "";
echo "<br>";
echo "IP Address: " . $row['Ip'] . "";
echo "<br>";
echo '<input type="checkbox" name="delchk[]" value="'.$row['id'].'" />';
echo "<br>";
echo "***********************************************";
echo "<br>";
}
echo "</table>";
mysql_close($con);
?>
Here is the code that when u press delete:
if (is_array($_POST['delchk'])) {
foreach ($_POST['delchk'] as $delId) {
$query = "DELETE FROM persons WHERE person_id = $delId";
$result = mysql_query($query);
if (!$result) {
die("Error deleting persons! Query: $query<br />Error: ".mysql_error());
}
}
}
I currently need like a button that when clicked will delete all rows and somehow refresh the page.
Here is the Php that shows all the members:
You will see a checkbox for delete.
<?php
require("inc/config.php");
$result = mysql_query("SELECT * FROM persons");
while($row = mysql_fetch_array($result))
{
echo "First Name: " . $row['FirstName'] . "";
echo "<br>";
echo "Last Name: " . $row['LastName'] . "";
echo "<br>";
echo "<a target=frame2 href='" ."profile.php?user1=". $row['FirstName'] ."'>Profile</a>";
echo "<br>";
echo "Date: " . $row['AddedDate'] . "";
echo "<br>";
echo "IP Address: " . $row['Ip'] . "";
echo "<br>";
echo '<input type="checkbox" name="delchk[]" value="'.$row['id'].'" />';
echo "<br>";
echo "***********************************************";
echo "<br>";
}
echo "</table>";
mysql_close($con);
?>
Here is the code that when u press delete:
if (is_array($_POST['delchk'])) {
foreach ($_POST['delchk'] as $delId) {
$query = "DELETE FROM persons WHERE person_id = $delId";
$result = mysql_query($query);
if (!$result) {
die("Error deleting persons! Query: $query<br />Error: ".mysql_error());
}
}
}
I currently need like a button that when clicked will delete all rows and somehow refresh the page.