我正在尝试使用复选框从表中删除一行。对于所有选中的复选框,全部删除。下面的代码不适用于多个复选框。它一次只会删除一行。有什么想法吗?我正在使用 pdo 显示行并使用 mysqli 准备好的语句进行删除。
<?php
if (isset($_POST['delete']))
{
if(!empty($_POST['id'])){
$stmt = $mydb->prepare("DELETE FROM products where username = ? and id = ? ");
echo $mydb->error;
$stmt->bind_param('ss', $username->username, $id);
foreach ($_POST['id'] as $id) {
$stmt->execute();
}
$errors = "Product Deleted.";
}
}
?>
<form action="" method="post">
<div>
<input type="submit" value="delete" name="delete">
<?php
/*
* Get and/or set the page number we are on
*/
if(isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
$options = array(
'results_per_page' => 10,
'url' => 'index.php?page=*VAR*',
'db_handle' => $dbh,
'using_bound_params' => true
);
try
{
$paginate = new pagination($page, "SELECT * FROM products where username = :param_a order by id desc", $options);
$paginate->bindParam(':param_a', $username->username, PDO::PARAM_STR, 12);
$paginate->execute();
}
catch(paginationException $e)
{
echo $e;
exit();
}
/*
* If we get a success, carry on
*/
if($paginate->success == true)
{
$paginate_result = $paginate->resultset->fetchAll();
foreach($paginate_result as $row)
{
?>
<input type='checkbox' name='id[]' class='check' value="<?php echo $row['id'];?>
<?php
echo $row['title'];
echo $row['description'];
}
}?>
</div>
</form>