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 7168813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:51:28+00:00 2026-05-28T14:51:28+00:00

I have a problem with my code in php. I would like to delete

  • 0

I have a problem with my code in php.
I would like to delete multiple lines from a table with select box when a users
press deleting button.

But I don’t have in my database an id field. So it’s difficult for me to do it
Could you help me please ?

 $user_query= "SELECT * FROM user";
    $user_result = mysql_query($user_query);
    $count=mysql_num_rows($user_result);

    echo "<form name='form1' method='post' action=''>";
    echo "<table>";
    echo "<tr>";
    echo "<th scope='col'>#</th>";
    echo "<th scope='col'>username</th>";
    echo "<th scope='col'>Email</th>";
    echo "<th scope='col'>tel</th>";
    echo "<th scope='col'>name</th>";
    echo "<th scope='col'>surname</th>";
    echo "<th scope='col'>type</th>";
    echo "</tr>";

    while($row = mysql_fetch_array($user_result))
    {
        echo "<tr>";
        echo '<td><input name="checkbox[]" type="checkbox" username="checkbox[]" value="'.$row['username'].'"></td>';
        echo '<td><b>'.$row['username'].'</b></td>';
        echo '<td><a href="mailto:'.$row['e_mail'].'" title="send Email">'.$row['e_mail'].'</a></td>';
        echo '<td>'.$row['phone_number'].'</td>';
        echo '<td>'.$row['name'].'</td>';
        echo '<td>'.$row['surname'].'</td>';
        echo '<td><img src="images/admin.png" width="40" height="45" title="admin"/></td>';
        echo '</tr>';
    }

    echo '<tr><td colspan="7"><input name="delete" type="submit" id="delete" value="Deleting"></td></tr>';
    echo "</table>";
    echo "</form>";



    if (isset($_POST['delete']))
    {
         // how can I take checkboxes value and delete values ??
         // $sql = "DELETE FROM user WHERE username=...;
        $result = mysql_query($sql);

        // if successful redirect
       if($result)
        {
          header("location: ShowUsers.php");
        } 
  }
  • 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-28T14:51:29+00:00Added an answer on May 28, 2026 at 2:51 pm

    As commented, If you have your username is unique identifier, Then replace with changes accordingly:=

            $user_query= "SELECT * FROM user";
                $user_result = mysql_query($user_query);
                $count=mysql_num_rows($user_result);
    
                echo "<form name='form1' method='post' action=''>";
                echo "<table>";
                echo "<tr>";
                echo "<th scope='col'>#</th>";
                echo "<th scope='col'>username</th>";
                echo "<th scope='col'>Email</th>";
                echo "<th scope='col'>tel</th>";
                echo "<th scope='col'>name</th>";
                echo "<th scope='col'>surname</th>";
                echo "<th scope='col'>type</th>";
                echo "</tr>";
    
                while($row = mysql_fetch_array($user_result))
                {
                    echo "<tr>";
                    echo '<td><input name="checkbox[]" type="checkbox" username="checkbox[]" value="'.$row['username'].'"></td>';
                    echo '<td><b>'.$row['username'].'</b></td>';
                    echo '<td><a href="mailto:'.$row['e_mail'].'" title="send Email">'.$row['e_mail'].'</a></td>';
                    echo '<td>'.$row['phone_number'].'</td>';
                    echo '<td>'.$row['name'].'</td>';
                    echo '<td>'.$row['surname'].'</td>';
                    echo '<td><img src="images/admin.png" width="40" height="45" title="admin"/></td>';
                    echo '</tr>';
                }
    
                echo '<tr><td colspan="7"><input name="delete" type="submit" id="delete" value="Deleting"></td></tr>';
                echo "</table>";
                echo "</form>";
    
    
    
                if (isset($_POST['delete']))
                {
                  if(!empty($_POST['checkbox'])){
                      $WhereCondition = $usernames = '';
                    foreach($_POST['checkbox'] as $user)
                      $usernames.= "'".$user."',";
                     $usernames = trim($usernames,',');
                     $WhereCondition = " username in($usernames) ";
                  }else{
                       $WhereCondition = " 0 ";
                   }
    
                     $sql = "DELETE FROM user where $WhereCondition ";
                    $result = mysql_query($sql);
    
                    // if successful redirect
                   if($result)
                    {
                      header("location: ShowUsers.php");
                    } 
              }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with Codeigniter routes. I would like to all registered users
I have a JavaScript file where I would like to include some php code.
I have a problem in php code inserting values into database (I use PHPMyAdmin).
I am using gettext in my PHP code, but I have a big problem.
I have a bizzare problem with php date function. code: $numDays = 8; $date
I have a web-site based on PHP, to which I would like to add
I have a problem I would like to compress all my javascript, but inside
I would like to archive a student by moving the record from one table
I would like to compare different PHP code to know which one would be
I am using Netbeans 6.7.1 to code in PHP. I have a problem with

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.