I have two table names called as "message" and "trash"
In "message" table, i've some data in table format contains (TO, SUBJECT, MSG, DATE) and i applied CHECKALL functionality with CHECKBOX using Jquery,
Now i want to perform when someone delete any row then it moves that row to another table i.e. into "trash"
Delete QUERY is perfectly Working so i want to modify this code... Here's my Code -
<form action="delete.php" method="post" name="data_table">
<table class="table table-hover table-striped">
<tbody>
<tr style="background-color:#222D32;">
<td><input type="checkbox" id="check_all" value=""></td>
<td><input name="submit" type="submit" value="Delete" id="submit" class="btn btn-default btn-sm"></td>
<td></td>
<td></td>
</tr>
<tr>
<td><input type="checkbox" value="<?php echo $rw['id']; ?>" name="data[]" id="data"></td>
<td><b><?php echo $rw['fto']; ?></td>
<td><b><?php echo $rw['subject']; ?></b></td>
<td><b><?php echo $rw['date']; ?></b></td>
<tr>
</tbody>
</table>
</form>
And here's the delete.php file
<?php
require_once("config.php");
if(isset($_POST['submit'])) {
$id_array = $_POST['data']; // return array
$id_count = count($_POST['data']); // count array
for($i=0; $i < $id_count; $i++) {
$id = $id_array[$i];
$query = mysqli_query($con, "DELETE FROM `message` WHERE `id` = '$id'");
if(!$query) { die(mysqli_error()); }
}
header("Location: sent.php"); // redirect after deleting
}
?>
Here's the JS File which i included at top
jQuery(function($) {
$("form input[id='check_all']").click(function() { // triggred check
var inputs = $("form input[type='checkbox']"); // get the checkbox
for(var i = 0; i < inputs.length; i++) { // count input tag in the form
var type = inputs[i].getAttribute("type"); // get the type attribute
if(type == "checkbox") {
if(this.checked) {
inputs[i].checked = true; // checked
} else {
inputs[i].checked = false; // unchecked
}
}
}
});
$("form input[id='submit']").click(function() { // triggred submit
var count_checked = $("[name='data[]']:checked").length; // count the checked
if(count_checked == 0) {
alert("Please select a row(s) to delete.");
return false;
}
if(count_checked == 1) {
return confirm("Are you sure you want to delete?");
} else {
return confirm("Are you sure you want to delete?");
}
});
});