I am creating a list of users that I would like to be able to either approve, deny, or delete. I don't want to do one by one, because it would be too much work.
I have the following code for the approve, deny, and delete columns:
<tr>
<input type="hidden" name="user_id" value="'.$row['user_id'].'">
<td style="text-align:center; padding:20px; background-color:#DFF0D8;">
<input type="radio" name="approve[]" value="1">
</td>
<td style="text-align:center; padding:20px; background-color:#FCF8E3;">
<input type="radio" name="approve[]" value="0">
</td>
<td style="text-align:center; padding:20px; background-color:#FCDEDE;">
<input type="radio" name="approve[]" value="3">
</td>
</tr>
I want to be able to set the "approved" column in the table "users" in MySQL to 1 if it is approved and to keep it to 0 if it is denied. If "delete" is chosen, then I want to be able to delete that row of data. How can I do this for a list of users? If it was just one by one it would be easy, but I don't know how to do it for multiple users.
I thought of looping through the "approve" array, but I can't change the values in the database because I don't know how to match this to a user_id.
Any help is appreciated.
</div>
here is a sample for multi delete:
index.php
<?php include('dbcon.php'); ?>
<form method="post" action="delete.php" >
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
<div class="alert alert-info">
<strong>Check the radion Button and click the Delete button to Delete Data</strong>
</div><thead>
<tr>
<th></th>
<th>FirstName</th>
<th>LastName</th>
<th>MiddleName</th>
<th>Address</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<?php
$query=mysql_query("select * from member")or die(mysql_error());
while($row=mysql_fetch_array($query)){
$id=$row['member_id'];
?>
<tr>
<td>
<input name="selector[]" type="checkbox" value="<?php echo $id; ?>">
</td>
<td><?php echo $row['firstname'] ?></td>
<td><?php echo $row['lastname'] ?></td>
<td><?php echo $row['middlename'] ?></td>
<td><?php echo $row['address'] ?></td>
<td><?php echo $row['email'] ?></td>
</tr>
<?php } ?>
</tbody>
</table>
<input type="submit" class="btn btn-danger" value="Delete" name="delete">
delete.php
<?php
include('dbcon.php');
if (isset($_POST['delete'])){
$id=$_POST['selector'];
$N = count($id);
for($i=0; $i < $N; $i++){
$result = mysql_query("DELETE FROM member where member_id='$id[$i]'");}
header("location: index.php"); } ?>
For multiple users you just need to add a dimension to all your form variable names:
<tr>
<td style="text-align:center; padding:20px; background-color:#DFF0D8;">
<input type="radio" name="approve[<?= $row['user_id'] ?>]" value="1">
</td>
<td style="text-align:center; padding:20px; background-color:#FCF8E3;">
<input type="radio" name="approve[<?= $row['user_id'] ?>]" value="0">
</td>
<td style="text-align:center; padding:20px; background-color:#FCDEDE;">
<input type="radio" name="approve[<?= $row['user_id'] ?>]" value="3">
</td>
</tr>
When the form is posted you will receive something like this:
approve[123]=1&approve[456]=2&...
This will turn $_POST['approve']
into an array:
array(
123 => 1
456 => 2
);
...