Php填充表格并更新


Php Populate Table and Update

伙计们,我不明白为什么我的代码只会更新表上的最后一行。它将用一个包含phpAdmin信息的表填充整个HTML页面。然后我可以在html页面上更改此信息。如果只有一条记录,超过一条,并且只在最后一行生效,那么一切都很好。我对这一切都是新手,所以请原谅代码,它在这里……

<html>
<?php

$con = mysql_connect("localhost","root");
if(!$con){
    die("Cant get there Bren: " . mysql_error());
}
mysql_select_db("Web_Data",$con);

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

    $UpdateQuery = "UPDATE Vehicles SET Vehicle_Id='$_POST[Vehicle_Id]',
    Registration='$_POST[Registration]',Make='$_POST[Make]',Model='$_POST[Model]',
    Classification='$_POST[Classification]',Rental_Price='$_POST[Rental_Price]',
    Current_Status='$_POST[Current_Status]',Mileage='$_POST[Mileage]' 
    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>
<tr>
<th>Vehicle_Id</th>
<th>Registration</th>
<th>Make</th>
<th>Model</th>
<th>Classification</th>
<th>Rental_Price</th>
<th>Current_Status</th>
<th>Mileage</th>
</tr></center>";
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>";

}
echo"</table>";
mysql_close($con);

?>
<br><br><br>
<footer>
        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--> 
</html>

请参阅此处:

使用while循环显示所有提取的记录。

<?php
// 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'];
}
?>

mysql_query不能使用多个查询。

最简单的方法就是单独运行它们。我相信你可以进行多查询,但我还没有尝试过。

只需了解如何使用foreach循环运行多个查询。

$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
}

这是我的错误

一个小时又一个小时,一切都是

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