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

  • Home
  • SEARCH
  • 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 8935209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:56:38+00:00 2026-06-15T09:56:38+00:00

I have a HTML form which I am using to update a MySQL table

  • 0

I have a HTML form which I am using to update a MySQL table via a post script – however, I am having an issue where the update buttons which are on each row only ever work for the last row in the table.

<?php

$link = mysql_connect ('localhost', 'root', 'password');
mysql_select_db ('cardatabase');

$select = 'SELECT * from cars';
$result = mysql_query($select, $link);

if(isset($_POST['update'])){
    $updatequery = "UPDATE cars SET 
        ID='$_POST[id]',
        CARMAKE='$_POST[carmake]',
        CARMODEL='$_POST[carmodel]',
        FUELTYPE='$_POST[fueltype]',
        TRANSMISSION='$_POST[transmission]',
        DOORS='$_POST[doors]',
        AMOUNT='$_POST[amount]',
        AVAILABLE='$_POST[available]'
        WHERE ID='$_POST[hidden]'";

    mysql_query($updatequery, $link);
};

echo '<table><form action=update.php method=post>';
echo '<tr><td>ID</td><td>Make</td><td>Model</td><td>Fuel Type</td><td>Transmission</td><td>Engine Size</td><td>Doors</td><td>Amount</td><td>Available</td></tr>';



while($row = mysql_fetch_array($result)) {
    echo '<tr>';
    echo "<td><input type='text' name='id' value='{$row['ID']}'</td>";
    echo "<td><input type='text' name='carmake' value='{$row['CARMAKE']}'</td>";
    echo "<td><input type='text' name='carmodel' value='{$row['CARMODEL']}'</td>";
    echo "<td><input type='text' name='fueltype' value='{$row['FUELTYPE']}'</td>";
    echo "<td><input type='text' name='transmission' value='{$row['TRANSMISSION']}'</td>";
    echo "<td><input type='text' name='enginesize' value='{$row['ENGINESIZE']}'</td>";
    echo "<td><input type='text' name='doors' value='{$row['DOORS']}'</td>";
    echo "<td><input type='text' name='amount' value='{$row['AMOUNT']}'</td>";
    echo "<td><input type='text' name='available' value='{$row['AVAILABLE']}'</td>";
    echo "<td><input type='hidden' name='hidden' value='{$row['ID']}'</td>";
    echo '<td><input type="submit" name="update" value="Update"</td>';
    echo '</tr>';
}

echo '</form></table>';
mysql_close ($link);

cars table:

MySQL 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-15T09:56:39+00:00Added an answer on June 15, 2026 at 9:56 am

    Let’s start with this for visibility:

    For future users seeing your questions. If you know this, great! Welcome to Stack Overflow! Please, don’t use mysql_* functions in new code. They are no longer maintained and the deprecation process has begun on it. See the red box? Learn about prepared statements instead, and use PDO or MySQLi – this article will help you decide which. If you choose PDO, here is a good tutorial.


    The problem you’re experiencing is caused by giving all of your inputs the same names (id, carmake etc). This means only the last row would ever be submitted.

    Give them names like so:

    name="id[]"
    

    That would make PHP treat the $_POST values as arrays, and you can access

    $_POST["id"][3]
    

    To get the fourth row (Starting from 0), for example.

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

Sidebar

Related Questions

I am creating one form in html using table. Which have one Drop down
I have a webpage with a form, which looks kinda like this: @using (Html.BeginForm(MyAction,
I have a form which I am using to update an existing set of
I have a html form which is populated using a java for loop. And
I have a field in my update form called approve which is using the
I have an HTML form which, when submitted by the user, will call a
I have an html form which when it gets submitted it calls a JavaScript
I have a html form which have a select list box from which you
I have this html form which has options: <tr> <td width=30 height=35><font size=3>*List:</td> <td
I have a HTML form which allows a user to add rows ad hoc

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.