Php 删除具有复选框值的行
我在使用复选框从数据库中删除行时遇到问题。我不知道如何使用复选框从数据库中删除多行。问题是,当我按下delete键时,它只会删除一个 我的PHP代码:Php 删除具有复选框值的行,php,html,checkbox,mysqli,Php,Html,Checkbox,Mysqli,我在使用复选框从数据库中删除行时遇到问题。我不知道如何使用复选框从数据库中删除多行。问题是,当我按下delete键时,它只会删除一个 我的PHP代码: // Here I didn't know how to put the value of all checkboxes into one variable. $intChk = $_POST['chk']; /* ..... */ foreach($intChk as $intRows) { // Starting t
// 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();
}
我的HTML代码:
<input type="checkbox" id="chk" class="checkbox" value="<?php echo $followId; ?>" name="chk[]">
像这样的东西
<?php
$stmt = $mysqli->prepare("DELETE FROM follow WHERE id = ?");
foreach($_POST['chk'] as $checkbox) {
$stmt->bind_param('s', intval($checkbox));
$stmt->execute();
}
$stmt->close();
您可以通过POST传递id数组,并使用foreach
循环……首先,如果您想根据复选框值删除多个记录,您应该收集所有选中要删除的复选框id。那你是怎么做到的?您应该使用JavaScript。可能是jQuery或其他JS库。@Leron如果您在HTML中创建几个具有相同名称但不同值的复选框输入,它将在PHP$\u POST变量中作为数组显示。我看不出使用JS库有任何意义…Barell谢谢,我使用了foreach循环,它成功了,谢谢!