I have a database setup to register members for a members only area of a site. I can echo all of the registered members with a checkbox so that I can choose to delete an individual member from an admin page, but I cant seem to figure out how to get the member chosen to be deleted when the submit button is clicked. I have tried to do it on a single page and on a 2 page process, first page lists the members with the checkbox which works to the point of choosing the member to be deleted, the difficulty I seem to be having is getting the members detail passed to the delete section of the code. Could anyone assist me please.
here is the delete_user.php which lists the members with a checkbox
<?php
include_once 'db_connect.php';
include_once 'functions.php';
sec_session_start();
//display users info with checkbox to delete
$sql = "SELECT * FROM `members` LIMIT 0, 30 ";
$result = mysqli_query($mysqli, $sql);
while($row = mysqli_fetch_array($result))
{
echo '<input type="checkbox" value="' .$row['username'] . '" name="delete[]" />';
// echo '<input type='checkbox' value='' .$row['adminid'] . '' name='delete[]' />';
echo ' ' .$row['username'];
echo ' ' .$row['email'];
echo '<br />';
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Delete Member</title>
</head>
<body>
<form>
<input name="submit" type="submit" formaction="delete_user.inc.php" formmethod="POST" value="Delete User">
</form>
</body>
</html>
here is the process page delete_user.inc.php
<?php
include_once 'db_connect.php';
include_once 'functions.php';
sec_session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
foreach($_POST['delete'] as $delete_user)
{
$sql = "DELETE FROM members WHERE memberid = '$delete_user'";
mysqli_query($mysqli, $sql) or die ('die now');
}
echo 'user has been deleted.<br />';
}
?>