删除复选框值,但当我单击按钮页面刷新时


Delete the checkbox values but when I click the button page refresh

嘿,我编写此代码是为了从数据库中删除选定的复选框值。是的,我知道这里已经有一些例子。但是当我看着他们并试图按照他们在他们的问题中所做的那样做。仍然没有得到成功。你们能帮我解决这个问题吗?当我单击删除按钮时,页面会刷新并显示记录已成功删除的消息,但之后看不到从数据库中删除的任何记录

<html>
    <head>
        <title>
        </title>
        <meta name="" content="">
    </head>
    <body bgcolor="#05fa8c">
        <form action="a.php" method="POST">
            <table style="margin-top: 252px; font-size: larger; font-style: oblique;" align="center" bgcolor="#05fa8c">
                <?php
                    include("config.php");  // Connect to database
                        //$id = $_POST['id'];
                        $sbook = "SELECT * FROM `book`";
                        $rnq   = mysqli_query($con,$sbook);
                        $count = mysqli_num_rows($rnq);
                        if(!$rnq)
                        {
                            print ("Error: %s'n ". mysqli_error($con));
                        }
                        echo "<table border=2 table style=margin-top: 252px; font-size: larger; font-style: oblique; bgcolor=#05fa8c>
                        <tr>
                        <td width=10% height= 10%><b>Book Name:</b></td>
                        <td width=10% height= 10%><b>Author Name:</b></td>
                        <td width=10% height= 10%><b>Publisher Name:</b></td>
                        <td width=10% height= 10%><b>Description</b></td>
                        <td width=3% height= 3% align='center'><b>#</b></td>
                        </tr>";
                        while($row = mysqli_fetch_array($rnq))
                        {
                            $rid   = $row['id'];
                            $bname = $row['bname'];
                            $aname = $row['aname'];
                            $pname = $row['pname'];
                            $desc  = $row['description'];
                            echo "<tr>
                            <td width=10% height= 10%><b>$bname</b></td>
                            <td width=10% height= 10%><b>$aname</b></td>
                            <td width=10% height= 10%><b>$pname</b></td>
                            <td width=10% height= 10%><b>$desc</b></td>";?>
                            <td align='center'><input type="checkbox" name="checkbox[<? echo $row['id']; ?>]" id="checkbox[<? echo $row['id']; ?>]" value="<? echo $row['id']; ?>"></td>
                    <?php   } ?>
                    </table>
                        <input type='submit' name='delete' id='delete' value='Delete'>
                        <?php
                              foreach($_POST['checkbox'] as $del_id){
                              $del_id = (int)$del_id;
                              $sql = 'DELETE FROM `book` WHERE `id` = '.$del_id;
                              mysqli_query($con, $sql);
                               echo "Records delete successfully";
                            }
                        ?>
        </form>
    </body>
</html>
将此

块移动到日期基线行之后:

<?php
    if (isset($_POST['delete'], $_POST['checkbox'])) {
        foreach($_POST['checkbox'] as $del_id){
            $del_id = (int)$del_id;
            $sql = 'DELETE FROM `book` WHERE `id` = '.$del_id;
            mysqli_query($con, $sql);
            echo "Records delete successfully";
        }
    }
?>