我正在尝试使用表单来更新数据库。数据库更新的问题是最后一行。所有行都由最后一行更新。问题出在哪里?谢谢
<?php if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$material = $_POST['material'];
$cena = $_POST['cena'];
$sql_material = "UPDATE material_tab SET material=:material, cena=:cena WHERE zapotrzebowanie_id = $id";
$statement_mat = $pdo->prepare($sql_material);
foreach ($material as $key => $value) {
$statement_mat -> bindValue(':material', $material[$key], PDO::PARAM_STR);
$statement_mat -> bindValue(':cena', $cena[$key], PDO::PARAM_STR);
$statement_mat -> execute();
}
$statement_mat -> closeCursor(); } ?>
形式:
<?php foreach ($rows_material as $material) { ?>
<tr>
<td><input type="checkbox" name="chk" /></td>
<td><input type="text" name="material[]" class="big_field required" value="<?php echo $material['material']; ?>" /></td>
<td><input type="text" name="cena[]" class="small_field" value="<?php echo $material['cena']; ?>" /></td>
</tr>
<?php } ?>