I have to POST selected input checkboxes using jquery to PHP. I inserted the array to an hidden input field. When I receive the array in PHP, only one userid is deleted. But I want all the selected userid to be deleted from the database.
My jquery code is:
$("#delSelected").click(function(){
var checks = [];
$.each($("#userList input:checked"), function(){
checks.push($(this).val());
});
$("#modal-user").html("Selected Users");
$("#modal-footer").html("<form action='' method='post'><input type='hidden' name='checkboxes[]' value='"+ checks +"'><button class='btn btn-warning btn-sm' type='submit' name='submit'>Yes Delete</button></form><button type='button' class='btn btn-secondary btn-sm' data-dismiss='modal'>Cancel</button>");
});
My PHP code is:
if(isset($_POST['submit'])){
$checkboxes = $_POST['checkboxes'];
foreach($checkboxes as $uId){
mysqli_query($con, "DELETE FROM users WHERE id = '$uId' ");
}
}
$uIdthis variable in checkbox loop?inquery also debug with print query in loop and execute on mysqlDELETE FROM users WHERE id = '2,4,5,6'. And? Is this a valid SQL syntax?