html - Php Populate Table and Update


Guys I cant see why it is that my code will only Update the last row on the table. It will populate the entire HTML page with a table with the info from phpAdmin. I can then change this info, on the html page. It all works fine if there is only one record, anymore than one and it only takes effect on the last row. I am new to all this, so excuse the code, here it is......



$con = mysql_connect("localhost","root");
    die("Cant get there Bren: " . mysql_error());

if (isset($_POST['update'])){

    $UpdateQuery = "UPDATE Vehicles SET Vehicle_Id='$_POST[Vehicle_Id]',
    WHERE Vehicle_Id='$_POST[hidden]'";

    echo "<center> Vechicle Id '$_POST[hidden]' succesfully VEHICLE UPDATED </center>";
    mysql_query($UpdateQuery, $con);


$sql = "Select * From Vehicles";
$myData = mysql_query($sql,$con);
echo" <center> <table border = 3>
while($record = mysql_fetch_array($myData)){
    echo "<form action = UpdateWD.php method=post>"; 
    echo "<tr>";
    echo "<td>" . "<input type = text name = Vehicle_Id value=" . $record['Vehicle_Id'] . " </td>";
    echo "<td>" . "<input type = text name = Registration value=" . $record['Registration'] . " </td>";
    echo "<td>" . "<input type = text name = Make value=" . $record['Make'] . " </td>";
    echo "<td>" . "<input type = text name = Model value=" . $record['Model'] . " </td>";
    echo "<td>" . "<input type = text name = Classification value=" . $record['Classification'] . " </td>";
    echo "<td>" . "<input type = text name = Rental_Price value=". $record['Rental_Price'] . " </td>";
    echo "<td>" . "<input type = text name = Current_Status value=" . $record['Current_Status'] . " </td>";
    echo "<td>" . "<input type = text name = Mileage value=" . $record['Mileage'] . " </td>";
    echo "<td>" . "<input type = hidden name = hidden value=" . $record['Vehicle_Id'] . " </td>";
    echo "<td>" . "<input type = submit name = update value= update" . " </td>";
    echo "</from>";



        Copyright © 2013 ABU LTD
<a href="about.html">About</a> -
<a href="policy.html">Privacy Policy</a> -
<a href="contact.html">Contact Us</a>
<a href="index.php" class="menu">Logout</a>
</footer> <!--footer--> 




See here:

Use while loop to display all fetched records.

// Make a MySQL Connection
$sql = "Select * From Vehicles";
$myData = mysql_query($sql,$con) or die(mysql_error());

while($row = mysql_fetch_array($myData)){
    echo $row['Vehicle_Id'];

And mysql_query can't use multiple queries.

The easiest thing is to just run them separately. I believe you can do multi query but I haven't tried it.

Just get the idea how you can run multiple queries using foreach loop.

$updateArray = array(21=>300,23=>200,24=>100);
foreach($updateArray as $id=>$value)
    $query = "UPDATE cart SET cart_qty='$value' WHERE cart_id = '$id'";
    mysql_query($query,$link);// $link is specified above



here is my mistake

hours and hours and all it was

echo "<td>" . "<input type = 'submit' name = 'update' value= 'update'" . " />";
    echo "</td>";
    echo "</tr>";
    echo "</form>";
had "form" spelt "from" & didnt close the </tr>

People are also looking for solutions to the problem: php - Pattern to match and replace words with upper and also lower case in them


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.