Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6037679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:06:35+00:00 2026-05-23T06:06:35+00:00

I want to delete multiple users from db table with checkboxes at once. But

  • 0

I want to delete multiple users from db table with checkboxes at once. But my code doesn’t work correctly
index.php

<?php 
require 'db.php';   
$query="SELECT * FROM usr_table";
$result = $db->query($query) or die(mysqli_error($mysqli));
$num=mysqli_num_rows($result) or die(mysqli_errno());
if ($result) {
    echo '
    <form method="post" action="delete.php">
    <table id="list">   
            while ($row = $result->fetch_object()) {
        $id = $row->id;
        $fullname = $row->fullname;
        $dob = $row->dob;
        $phone= $row->phone;
        $adress= $row -> adress;
        $school = $row->school;
echo '<tr>
<td>'.$id.'</td>
<td>'.$fullname.'</td>
<td>'.$dob.'</td>
<td>'.$phone.'</td>
<td>'.$adress.'</td>
<td>'.$school.'</td>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]"  method="post" value=$id />
</tr>';
    }

    // when the loop is complete, close off the list.
    echo "</table><p><input id='delete' type='submit' class='button' name='delete' value='Delete Selected Items'/></p></form>";
    }
?>

delete.php

<?php

    require 'db.php';
    $delete=$_GET['delete'];

    if($delete) // from button name="delete"
    {
        $checkbox = $_GET['checkbox']; //from name="checkbox[]"
        $countCheck = count($_GET['checkbox']);

        for($i=0;$i<$countCheck;$i++)
        {
            $del_id  = $checkbox[$i];
            $sql = "DELETE from usr_table where id = '$del_id'";
            $result = $db->query($sql) or die(mysqli_error($db));

        }
            if($result)
        {   
                header('Location: index.php');
            }
            else
            {
                echo "Error: ".mysqli_error($db);
            }
    }

?>

db.php

<?php
$db = new mysqli('localhost', 'user' ,'pass', 'table') or die(mysqli_errno());
$db->query("SET names UTF8") or die(mysqli_errno());
foreach ($_POST as $key => $value) { 
$_POST[$key] = mysqli_real_escape_string($value);
}
?>

Please help! It doesn’t work
HTML version

<form method="post" action="delete.php">
    <table id="list">   
            <thead>
                <tr>
                    <th width="5%">ID</th>

                    <th width="35%">Ad və soyad</th>
                    <th width="15%">Təvəllüd</th>
                    <th width="15%">Telefon</th>
                    <th width="20%">Ünvan</th>
                    <th width="5%">Məktəb</th>
                    <th width="5%">#</th>

                </tr>
            </thead><tr>
<td>20</td>
<td>Tural Teyyuboglu</td>
<td>1992-06-09</td>
<td>4940301</td>
<td>Baki Yasamal Zergerpalan</td>
<td>189</td>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]"  method="post" value="20 "/>

</tr><tr>
<td>22</td>
<td></td>
<td>1992-06-09</td>
<td>0</td>
<td></td>
<td></td>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]"  method="post" value="22 "/>
</tr><tr>
<td>23</td>
<td>Tural Turik</td>
<td>1992-06-09</td>

<td>4940301</td>
<td>Bakı Yasamal Zərgerpalan</td>
<td>189</td>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]"  method="post" value="23 "/>
</tr><tr>
<td>24</td>
<td>Tural Əliyev</td>
<td>1992-06-09</td>
<td>4940301</td>
<td>Bakı Y </td>

<td></td>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]"  method="post" value="24 "/>
</tr><tr>
<td>25</td>
<td>Zammbbb</td>
<td>1992-06-09</td>
<td>4940301</td>
<td>Bakı Uadnf` skbnfias</td>
<td>189</td>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]"  method="post" value="25 "/>
</tr><tr>

<td>26</td>
<td>Tural Əliyev</td>
<td>1992-06-09</td>
<td>0</td>
<td>  </td>
<td></td>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]"  method="post" value="26 "/>
</tr></table><p><input id='delete' type='submit' class='button' name='delete' value='Delete Selected Items'/></p></form>                </td>
            </tr>
    </table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:06:36+00:00Added an answer on May 23, 2026 at 6:06 am

    There are a few things wrong here..

    1) Your form method="POST". In your delete.php, you are using $_GET['checkbox'].

    Use $_POST['checkbox'] instead. ($_GET['delete'] needs to be $_POST['delete']).

    2) You’re echoing PHP code:

    if ($result) {
    
    echo '
    <form method="post" action="delete.php">
    <table id="list">   
            while ($row = $result->fetch_object()) {
        $id = $row->id;
        $fullname = $row->fullname
    

    You need to end your echo statement before continuing with PHP code:

    if ($result) {
    
        echo<<<formheader
        <form method="post" action="delete.php">
        <table id="list">   
    formheader;
    
        while ($row = $result->fetch_object()) {
            $id = $row->id;
            $fullname = $row->fullname
    

    3 & 4) Put quotes around your values in your input element, like so:

    <input type="checkbox" name="checkbox[]" id="checkbox" value="$id" />
    

    And if you’re going to echo like that, then escape your double quotes since it is in an echo statement:

    <input type=\"checkbox\" name=\"checkbox[]\" id=\"checkbox\" value=\"$id\" />
    

    5) Your $_POST sanitizing is what is emptying your multi-dimensional $_POST[‘checkbox’] array from db.php.

    When I remove this from db.php

    foreach ($_POST as $key => $value) { 
        $_POST[$key] = mysqli_real_escape_string($value);
    }
    

    Then your print_r($_POST) should display your values. Assuming everything else is alright, that should work. However, you’ll need to reconsider how you sanitize your POST variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to delete foo() if foo() isn't called from anywhere.
I want to delete all but the 4 newest directories in my parent directory.
I'm writing an application in PHP 5. I want to delete some rows in
I want to perform cascade delete for some tables in my database, but I'm
I want to use the recursive_directory_iterator offered by boost::filesystem to delete a directory. But
I want to query a result from a table. The problem I run into
If all tables I want to delete from have the column gamer_id can i
Can we add multiple rows in the database table from one JSF page in
Hey guys i wrote a quick test. I want delete to call deleteMe which
I want to delete a folder that contains thousands of files and folders. If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.