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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:43:11+00:00 2026-06-16T19:43:11+00:00

I need your advice. I fetch data from database to table: ID, Name. In

  • 0

I need your advice. I fetch data from database to table: ID, Name.
In table are Actions: Delete, Enable, Block. When action Delete
is selected, I would like, that respectively record will be deleted.
However, my script does not work and always delete last record, even I select
another record. I think problem is, that select name and hidden input
name is similar for all records. But I can not find way, how to create
them with different names.
Any advice is welcome.

HTML:

  <form method='post'> 
  <table border='1'>
  <tr>
  <th> ID </th>
<th> Name </th>
<th> Action </th>
</tr>

Code:

$db = new PDO('mysql:host=localhost;dbname=****;charset=utf8', '**', '**');
$query = $db->query("SELECT ID,statusas,login,vardas,email FROM users");

while($row = $query->fetch(PDO::FETCH_BOTH)) { 
 echo "<tr><input type='hidden' name='id' value='".$row[0]."'>";
 echo "<td>".$row[0]."</td>";
 //echo "<td>".$row[1]."</td>";
 echo "<td>".$row[2]."</td>";
 //echo "<td>".$row[3]."</td>";
// echo "<td>".$row[4]."</td>";
 echo "<td><select name='action'>
             <option value='choose'>Choose..</option>
             <option value='delete'> Delete </option>
             <option value='enable'> Enable </option>
             <option value='block'> Block</option>
        </select></td>";
   echo "</tr>";
 }
 echo "<br><input type='submit' name='submit'></table></form>";

 if($_POST['submit']) {
   if ($_POST['action']== 'delete') {
   echo $_POST['id']; // delete query, but now I am just checking if I get a proper ID.
  }
}
else {
echo "bad";
}

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-06-16T19:43:12+00:00Added an answer on June 16, 2026 at 7:43 pm

    You are using the same name attribute on every row in the form, so they are being overridden and it’s using the last one.

    What you could do is either wrap every row in its own form, or you could do something like this, and have only 1 submit button to execute the action on every row:

    // remove hidden id element
    
    ...
    
    echo "<td><select name='action[" . $row[0] . "]'>"
    
    ...
    // remove submit button in the loop, but add it after the while loop
    ...
    
    if (isset($_POST['action']))
    {
        foreach ($_POST['action'] as $id => $action)
        {
            if ($action !== 'choose')
            {
                // do action on the id;
                echo $id . " -> " . $action . "<br>";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need your advice and help i fetched an array of data from the
I need your advice on this piece of code: the table fields options[0], options[1]
I need your advice about framework selection (Java vs Mono) for a new large
Basically I need your advice my good stack friends :D For the last six
I am a beginner concerning development in C# and I need your advice to
I am developing a WPF application, and I need your advice. I have to
I have no ideas how to do this, so I need your advice. I
I need your advice deciding on a new project architecture I'm going to implement.
I need your advice. We have an already working web resource management application, we
I'm building my personal CMS and need your advice organizing core functions and classes.

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.