Reputation: 167
I'm having problems with deleting rows from the DB with checkboxes. I don't know how to delete multitple rows from the DB with checkboxes. The problem is that when I press delete it will only delete one.
My PHP code:
// Here I didn't know how to put the value of all checkboxes into one variable.
$intChk = $_POST['chk'];
/* ..... */
foreach($intChk as $intRows)
{
// Starting the process to delete the selected rows.
$stmt = $mysqli->prepare("DELETE FROM follow WHERE id = ?");
$stmt->bind_param('s', $intChk);
$stmt->execute();
$stmt->close();
}
My HTML code:
<input type="checkbox" id="chk" class="checkbox" value="<?php echo $followId; ?>" name="chk[]">
Thank you for your helping!
Upvotes: 0
Views: 85
Reputation: 34093
Something like this?
<?php
$stmt = $mysqli->prepare("DELETE FROM follow WHERE id = ?");
foreach($_POST['chk'] as $checkbox) {
$stmt->bind_param('s', intval($checkbox));
$stmt->execute();
}
$stmt->close();
Upvotes: 2