Php 通过签出多次删除

Php 通过签出多次删除,php,Php,我卡在我的一个应用程序模块中。我必须在应用程序中设置多个删除选项。 我使用了下面的代码。这个设计非常好。我想在其中添加多个删除选项的所有内容。 以下是我试用过的代码: <html> <head> <title>Strad Hosting Limited -Web Hosting</title> <script language="javascript"> function validate() { var chks = doc

我卡在我的一个应用程序模块中。我必须在应用程序中设置多个删除选项。 我使用了下面的代码。这个设计非常好。我想在其中添加多个删除选项的所有内容。
以下是我试用过的代码:

<html>
<head>
<title>Strad Hosting Limited -Web Hosting</title>

<script language="javascript">
function validate()
{
    var chks = document.getElementsByName('checkbox[]');
    var hasChecked = false;
    for (var i = 0; i < chks.length; i++)
    {
        if (chks[i].checked)
        {
            hasChecked = true;
            break;
        }
    }
    if (hasChecked == false)
    {
        alert("Please select at least one.");
        return false;
    }
    return true;
}
</script>

</head>
<body >

<?php
    $con=mysqli_connect("localhost","stradsol","D#v,b5TnQ!D!","stradsol_sales");
    if (mysqli_connect_errno())
    {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $result = mysqli_query($con,"SELECT * FROM Persons");

    echo "<form name='form1' method='post' action='' onSubmit='return validate();'>";
    echo "<table border='1' style='
            background-color: white;'>
            <tr>
                <th></th>
                <th>id</th>
                <th style='padding-left: 11px;'>Lead Generated Date   </th>
                <th>name</th>
                <th>email</th>
                <th>contacts</th>
                <th>requirement</th>
                <th style='display:none;'>Company name</th>
                <th style='display:none;'>Address</th>
                <th>Next Follow-Up date</th>
                <th>Final_Details</th>
                <th style='display:none;'>Status</th>
                <th style='padding-left: 12px; display:none;'>Lead Closed Date</th>
                <th>EDIT</th>
                <th>Follow-up History</th>
                <th>Add Follow-up</th>
                <th>Delete Record</th>
            </tr>";

    while($row = mysqli_fetch_array($result))
    {
        echo "<tr>";
        echo "<td><input name='checkbox[]' type='checkbox' id='checkbox[]' value='".$rows['id']."'></td>";
        echo "<td>" . $row['id'] . "</td>";
        echo "<td>" . $row['date'] . "</td>";
        echo "<td><a href='config_info.php?id=" . $row['id'] . "'>".$row['name']."</a></td>";
        echo "<td>" . $row['email'] . "</td>";
        echo "<td>" . $row['contacts'] . "</td>";
        echo "<td>" . $row['requirement'] . "</td>";

        echo "<td style='display:none;'>" . $row['company_name'] . "</td>";
        echo "<td style='display:none;'>" . $row['address'] . "</td>";
        echo "<td>" . $row['startdate'] . "</td>";
        echo "<td>" . $row['final_details'] . "</td>";
        echo "<td style='display:none;'>" . $row['status'] . "</td>";
        echo "<td style='display:none;'>" . $row['lead_close'] . "</td>";
        echo "<td><a href='edit_eg1.php?id=" . $row['id'] . "'>Edit</a></td>";
        echo "<td><a href='Follow_history.php?id=" . $row['id'] . "'>Follow_history</a></td>";
        echo "<td><a href='add_follow.php?id=" . $row['id'] . "'>Followup</a></td>";
        echo "<td><a href='delete.php?id=" . $row['id'] . "'>Delete</a></td>";
        echo "</tr>";
    }
    echo "<tr><td><input name='delete' type='submit' id='delete' value='Delete'></td></tr>";

    $count=mysqli_num_rows($result);
    if(isset($_POST['delete'])){
        for($i=0;$i<count($_POST['checkbox']);$i++){
            $del_id=$_POST['checkbox'][$i];
            $sql = "DELETE FROM Persons WHERE id='$del_id'";
            echo $sql;
            $result2 = mysqli_query($con,$sql);
        }

        // if successful redirect to delete_multiple.php
        if($result2)
        {
            echo "<meta http-equiv=\"refresh\" content=\"0;URL=edit_table_del.php\">";
        }   
    }

    mysqli_close($con);
    echo "</table>";
    echo "</form>";
?>

<br><br>
<a href="index2.php">[ Back To Home ]</a>

</body>
</html>

斯特拉德托管有限公司-网络托管
函数验证()
{
var chks=document.getElementsByName('checkbox[]);
var hasChecked=false;
对于(变量i=0;i
$sql = "DELETE FROM Persons WHERE id='$del_id'";


我假设ID是一个数字,因此不需要单引号。

您能否只在发生错误的地方添加代码?如果不确定问题的确切位置,可以使用
var\u dump()
打印变量并检查在何处产生意外结果。
$sql = "DELETE FROM Persons WHERE id=$del_id";