php - Multiple delete through checkout


I am stuck in one of my application module. I have to set multiple delete options in my application. I have used the below code. The designing is perfectly fine. All what I want to add multiple delete options in it.
Below is the code which I have tried out:

<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;
    if (hasChecked == false)
        alert("Please select at least one.");
        return false;
    return true;

<body >

    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;'>
                <th style='padding-left: 11px;'>Lead Generated Date   </th>
                <th style='display:none;'>Company name</th>
                <th style='display:none;'>Address</th>
                <th>Next Follow-Up date</th>
                <th style='display:none;'>Status</th>
                <th style='padding-left: 12px; display:none;'>Lead Closed Date</th>
                <th>Follow-up History</th>
                <th>Add Follow-up</th>
                <th>Delete Record</th>

    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>";

            $sql = "DELETE FROM Persons WHERE id='$del_id'";
            echo $sql;
            $result2 = mysqli_query($con,$sql);

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

    echo "</table>";
    echo "</form>";

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


I am stuck, the query is not working I think. I don't know what I am missing.




Try replacing

$sql = "DELETE FROM Persons WHERE id='$del_id'";


$sql = "DELETE FROM Persons WHERE id=$del_id";

I'm assuming the ID is a number so the single quotes aren't needed.

People are also looking for solutions to the problem: javascript - File not received at server using FormData


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.