So, here I have a table that shows the data in the MySQL Database. I have attached checkbox in the first row which selects the names to be deleted which are unique. How can I delete checked data in the form from Database using array or any other ways in PHP.
Here's my code,
My PHP script to show data,
<form method='POST' action='../../panel/delete_others.php'>
<table id='example1' class='table table-bordered table-hover'>
<thead>
<tr>
<th>Mark User </th>
<th>User name</th>
<th>User Password</th>
<th>User Type</th>
<th>User Status</th>
</tr>
</thead>
<tbody>";
while($row = mysqli_fetch_array($result2)){
echo "<tr>
<td> <input type='checkbox' name='others_delete[]' value='".$row['USER_NAME']."'/></td>
<td>".$row['USER_NAME']."</td>
<td>".$row['USER_PASSWORD'].
"</td>
<td>".$row['USER_type']."</td>
<td>".$row['USER_STATUS']."</td>
</tr>";
}
echo "</tbody>
</table>
</form>
My PHP script to delete data,
<?php
include('config.php');
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['others_delete'])){
foreach($_POST['others_delete'] as $selected){
$sql ="DELETE FROM users WHERE USER_NAME='$selected' and USER_type='Others'";
echo $selected;
if(mysqli_query($db, $sql)){
mysqli_query($db, $sql);
}
else{
echo "error: ".$sql. "<br>" . mysqli_error($db);
}
}
}
}
mysqli_close($db);
?>
So, the code i written seem right but whenever i hit submit button i get blank page.