0

我很难看到这里出了什么问题。我正在尝试根据已选中的复选框从我的数据库中删除。if(!empty($_POST['removeCheckbox'])) 说 removeCheckbox 是空的,即使我回显 $currentRow[] 它显示值。提前致谢。

while($row = mysqli_fetch_array($paperToReview)){    
    if ($row > 0) {
        $currentRow = array($row['uid'], $row['toReview']);
                echo $currentRow[0];
                echo $currentRow[1];            
        echo '<td width = 200><input type="checkbox" name="removeCheckbox[]" value="'.$currentRow.'"> Remove</td>';
    }
}
//Remove button
echo'<td width = 200><td width = 200><td width = 200><td width = 200><td width = 200><input type=submit name=submit value="Remove Checked Rows"></td>';

然后在这里我查看删除按钮是否已被选中并查看所有选中的框。

    if (isset($_POST['submit']) && $_POST['submit'] =="Remove Checked Rows"){
        if(!empty($_POST['removeCheckbox'])) {
        //deletes row from database
            foreach($_POST['removeCheckbox'] as $check) {
                    DBSubmit("DELETE FROM paper_review WHERE paper_reviewer_id = '" . $check[0] ."' AND paperid = '" . $check[0] ."'");

                }
        }
4

2 回答 2

0

你确定,满足条件吗?

检查 $_POST 变量中的值是否正确,在提交条件之前简单地写下这样的内容

echo(<pre>); print_r($_POST); echo(</pre>);

请发送更多代码(如何创建表单,post 变量中的内容)

T。

于 2013-05-13T21:29:06.893 回答
0

这将使所有值都成为“数组”,因为您不能直接回显数组试试这个:

while($row = mysqli_fetch_array($paperToReview)){    
    if ($row > 0) {
        $currentRow = array($row['uid'], $row['toReview']);         
        echo '<td width = 200><input type="checkbox" name="removeCheckbox[]" value="'.json_encode($currentRow).'"> Remove</td>';
    }
}
//Remove button
echo'<td width = 200><td width = 200><td width = 200><td width = 200><td width = 200><input   type=submit name=submit value="Remove Checked Rows"></td>';

在控制器代码中

    if (isset($_POST['submit']) && $_POST['submit'] =="Remove Checked Rows"){
    if(!empty($_POST['removeCheckbox'])) {
    //deletes row from database
        foreach($_POST['removeCheckbox'] as $jsonCheck) {
                $check = json_decode($jsonCheck);
                DBSubmit("DELETE FROM paper_review WHERE paper_reviewer_id = '" . $check[0] ."' AND paperid = '" . $check[0] ."'");

            }
    }

您可以将 json_encode/decode 替换为 serialize/unserialize 或任何其他方法

于 2013-05-13T21:37:50.747 回答