gpt4 book ai didi

php - 无法获取基于 mysql 查询的表单来加载所有 POST 变量

转载 作者:行者123 更新时间:2023-11-29 22:28:55 24 4
gpt4 key购买 nike

尝试从 mysql 查询创建表单,我可以在其中更新每行上的字段。然而,它只是发布我的最后一行。这是我所拥有的。

    require('includes/application_top.php');
if (!empty($_POST['inventory_daily-submit'])) {
foreach($_POST['id'] as $id) {
print_r($_POST);}
} ?>
<form name="inventory_daily" method="post">
<table>
<tr>
<td>Product #</td>
<td>Product Name</td>
<td>Count Unit</td>
<td>Begining Quantity</td>
<td>Ending Quantity</td>
<td>Unit Price</td>
</tr>
<input name="id[]" type="hidden" size="3" maxlength="3">
<?php
$inventory = $db->Execute('select product_id, product_name, quantity_on_hand, count_unit, case_price, unit_price, active, category_id from ' . TABLE_INVENTORY . ' WHERE active = 0 order by category_id ASC');
while(!$inventory->EOF) {
?>
<tr>
<td><?php echo $inventory->fields['product_id']; ?><input name="product_id" type="hidden" size="3" maxlength="3" value="<?php echo $inventory->fields['product_id']; ?>"></td>
<td><?php echo $inventory->fields['product_name']; ?></td>
<td><?php echo $inventory->fields['count_unit']; ?></td>
<td><?php echo $inventory->fields['quantity_on_hand']; ?>
<input name="old_quantity" type="hidden" size="7" maxlength="7" value="<?php echo $inventory->fields['quantity_on_hand']; ?>"></td>
<td><input name="<?php echo "new_quantity_on_hand"; ?>" type="text" size="7" maxlength="7"></td>
<td><?php echo $inventory->fields['unit_price']; ?>
<input name="unit_price" type="hidden" size="7" maxlength="7" value="<?php echo $inventory->fields['unit_price']; ?>">
<input name="case_price" type="hidden" size="7" maxlength="7" value="<?php echo $inventory->fields['case_price']; ?>"></td>
</tr>
<?php
$inventory->MoveNext();
}

?>
</table>
<input type="submit" name="inventory_daily-submit">
</form>

表单显示 3 行。

1 cheerwine each 33 ____ .38
2 cool blue each 11 ____ .66
3 diet peps each 13 ____ .51

在每一行中,我输入的 new_quantity_on_hand 的数字都小于 old_quantity

所以我有 3 行应该在下划线所在的位置发布数字 32、10 和 12,但只有最后一行发布。

输出是:

Array ( [id] => Array ( [0] => ) [product_id] => 3 [old_quantity] => 13.0 [new_quantity_on_hand] => 12 [unit_price] => 0.51 [case_price] => 12.25 [inventory_daily-submit] => Submit Query )

最佳答案

if (!empty($_POST['product_id'])) {
$date = date('Y-m-d');
$i=0;
$m=count($_POST['product_id']);
echo $m; echo "<br>";
while ($i < $m) {
if(!empty($_POST['new_quantity_on_hand'][$i])){
$old = $_POST['old_quantity'][$i];
$new = $_POST['new_quantity_on_hand'][$i];

$sql_data_array = array('product_id' => $_POST['product_id'][$i],
'quantity_on_hand' => $_POST['new_quantity_on_hand'][$i],);

}
echo "Information has been successfully saved!<br>";
}
$i++;
}

}

关于php - 无法获取基于 mysql 查询的表单来加载所有 POST 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30004916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com