我在更新数据库中的多行时遇到问题。这是我的形式。SQL只更新最后一行
<form action="results-action" method="post" enctype="multipart/form-data">
<fieldset>
<table id ="table_id" class="display">
<thead>
<tr><td><h2>Pending Order</h2></td></tr>
<tr>
<th scope="col">Order ID</th>
<th scope="col">Name</th>
<th scope="col">Address</th>
<th scope="col">Product Name</th>
<th scope="col">Produt Quantity</th>
<th scope="col">Price</th>
<th scope="col">Order status</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><input type="text" value='<?=$row['virtuemart_order_id']?>' name="orderid" id="virtuemart_order_id"></td>
<td><?=$row['first_name']?></td>
<td><?=$row['address_1']?></td>
<td><?=$row['order_item_name']?></td>
<td><?=$row['product_quantity']?></td>
<td><?=$row['product_final_price'] ?></td>
<td><select name='change'>
<option value='P'> Pending</option>
<option value='C'> Confirmed</option></select></td>
</tr>
<?php
}
?>
</tbody>
</table>
</fieldset>
<fieldset>
<table>
<tr>
<td><input type="submit" value="Update status" name="update status"> </td>
</tr>
</table>
</fieldset>
</form>
当我更改订单状态以确认每个行时,它应该将订单状态更新为每行的'P'。但是,它只更新最新的行。
这是我的更新代码。
$change = $_POST["change"];
$orderid = $_POST['orderid'];
// build SQL statement
$query = "update ruj3d_virtuemart_order_items set order_status= '$change' WHERE virtuemart_order_id = '$orderid'";
// execute SQL statement
$status = mysqli_query($link, $query) or die(mysqli_error($link));
if ($status) {
echo "<big>It has been updated !!. </big>";
}else {
echo "<br>Has not been successfully confirmed</br>";
}
我已经删除了大量不必要的空格中。在我看来,你的HTML仍然不可读。你能减少你发布的数量吗?它甚至相关吗? – Ben
所有ids必须是唯一的,你知道。 – Daedalus