当我选择与更新表单中选中的不同的另一个收音机时,我无法更改数据库内的一行中的值...总是返回以前的状态...我怎样才能使它工作?
以下是捕获:
- 如何检查收音机
- 成功讯息
但是当我刷新窗口时,检查的输入总是前一个。
这是代码:
//form:
.....
<td>
<input type="text" value="<?php echo $venta; ?>" name="venta[]" id="venta_<?php echo $i; ?>" class="form-control" autocomplete="off" placeholder="Precio de venta" required="required"/>
</td>
<td>
<input type="radio" name="principal[]" id="principal_<?php echo $i; ?>" <?php if($principal == 1){ echo 'value="0" checked="checked"';} else { echo 'value="1"';}; ?>>
</td>
.....
</tr>
//the insert/update code:
$sql = "INSERT INTO MEDIDAS (idMed, principal, cod, presentacion, cantidad, compra, venta, id_user)
VALUES ";
$insertQuery = array();
$insertData = array();
foreach ($_POST['venta'] as $i => $venta) {
$insertQuery[] = '(?, ?, ?, ?, ?, ?, ?, ?)';
$insertData[] = $_POST['idMed'][$i] == '' ? null : $_POST['idMed'][$i];
$insertData[] = $_POST['principal'][$i] == '' ? 0 : $_POST['principal'][$i]; //this is the row with the input radio
$insertData[] = $code;
$insertData[] = $_POST['presentacion'][$i];
$insertData[] = $_POST['existencia1'][$i];
$insertData[] = $_POST['compra'][$i];
$insertData[] = $_POST['venta'][$i];
$insertData[] = $id_user;
}
if (!empty($insertQuery)) {
$sql .= implode(', ', $insertQuery);
$sql .= " ON DUPLICATE KEY UPDATE
principal = VALUES (principal), cod = VALUES (cod), presentacion = VALUES (presentacion), cantidad = VALUES (cantidad),
compra = VALUES (compra), venta = VALUES (venta), id_user = VALUES (id_user)
";
$stmt = $conn->prepare($sql);
$stmt->execute($insertData);
}