在php和mysql中选择时如何删除多个复选框?

在php和mysql中选择时如何删除多个复选框?,php,mysql,Php,Mysql,我对如何一次删除选中的复选框感到非常困惑和混乱。有人能帮忙吗?我尝试过许多删除代码,并在失败后对其进行了注释。所以请建议!!!! 下面的代码是为“全部删除”按钮编写的 “删除选择”按钮上的一些轨迹 或 if($delete){ 对于($i=0;$i) “全部删除”按钮类型 <button type="submit" id="delete" name="delete" value="delete" data-loading-text="Loading...">Delete All&

我对如何一次删除选中的复选框感到非常困惑和混乱。有人能帮忙吗?我尝试过许多删除代码,并在失败后对其进行了注释。所以请建议!!!! 下面的代码是为“全部删除”按钮编写的

“删除选择”按钮上的一些轨迹

if($delete){
对于($i=0;$i)
“全部删除”按钮类型

<button type="submit" id="delete" name="delete" value="delete"  data-loading-text="Loading...">Delete All</button>
全部删除
所选删除的按钮类型

    <button type="submit" id="deletes" name="delete" value="delete"  data-loading-text="Loading..." onClick="delete_check.php">Delete Selected</button>
删除所选内容
桌子是这样的

<table class="table table-bordered">
                <tr>
                    <th>Title</th>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Mobile</th>
                    <th>Phone</th>
                </tr>
                <?php
                    $res=mysql_query("SELECT * FROM dealer_tbl");
                    while($dealer_row=mysql_fetch_array($res))
                    {
                    ?>
                        <tr>

                            <td><?php echo $dealer_row['title']; ?></td>
                            <td><?php echo $dealer_row['firstname']; ?></td>
                            <td><?php echo $dealer_row['lastname']; ?></td>
                            <td><?php echo $dealer_row['email']; ?></td>
                            <td><?php echo $dealer_row['phone']; ?></td>
                            <td align="center"><a href='dealer_edit.php?did=<?=$dealer_row['uid']?>'>Edit</a> | <a href='dealer_delete.php?did=<?=$dealer_row['uid']?>'>Delete</a></td>
                            <td><input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $dealer_row['uid']; ?>"  />
    </td> 
                        </tr>
                    <?php
                    }
                ?>
            </table>
    </div>

标题
名字
姓
可移动的
电话
| 

简易解决方案,[在自己动手模式下]

  • 将复选框命名为
    Name=“checkbox[$row[id]]”“
  • 当这些复选框被提交时,您将得到一个数组,其中Key是要删除的ID
  • 提取数组键,在逗号分隔列表中内爆它们
  • 运行SQL查询
    delete from table where id in()
  • 你自己试试,快乐地生活

  • 将表格也放在
    标记内。在这种情况下,复选框的参数将收到。

    您的正确答案是:

    <?php
    $delete=$_POST['delete'];
    $chkbox=$_POST['checkbox'];
    if($delete){
      for($i=0;$i<count($chkbox);$i++){
        $del_id = $chkbox[$i];
        $sql = "DELETE FROM $dealer_tbl WHERE id='$del_id'";
        $result = mysql_query($sql);
      }
     ?>
    

    看起来您粘贴了整个文件,而不是特定的代码块。@SumitBijvani现在清楚了吗?您能检查并提供帮助吗?谢谢您的评论:)
    
        <button type="submit" id="deletes" name="delete" value="delete"  data-loading-text="Loading..." onClick="delete_check.php">Delete Selected</button>
    
    <table class="table table-bordered">
                    <tr>
                        <th>Title</th>
                        <th>First Name</th>
                        <th>Last Name</th>
                        <th>Mobile</th>
                        <th>Phone</th>
                    </tr>
                    <?php
                        $res=mysql_query("SELECT * FROM dealer_tbl");
                        while($dealer_row=mysql_fetch_array($res))
                        {
                        ?>
                            <tr>
    
                                <td><?php echo $dealer_row['title']; ?></td>
                                <td><?php echo $dealer_row['firstname']; ?></td>
                                <td><?php echo $dealer_row['lastname']; ?></td>
                                <td><?php echo $dealer_row['email']; ?></td>
                                <td><?php echo $dealer_row['phone']; ?></td>
                                <td align="center"><a href='dealer_edit.php?did=<?=$dealer_row['uid']?>'>Edit</a> | <a href='dealer_delete.php?did=<?=$dealer_row['uid']?>'>Delete</a></td>
                                <td><input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $dealer_row['uid']; ?>"  />
        </td> 
                            </tr>
                        <?php
                        }
                    ?>
                </table>
        </div>
    
    <?php
    $delete=$_POST['delete'];
    $chkbox=$_POST['checkbox'];
    if($delete){
      for($i=0;$i<count($chkbox);$i++){
        $del_id = $chkbox[$i];
        $sql = "DELETE FROM $dealer_tbl WHERE id='$del_id'";
        $result = mysql_query($sql);
      }
     ?>