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

标签 php mysql arrays

尝试从 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/

相关文章:

php - 数组高一级

C++实现计数排序

php - jQuery AJAX 在发送到服务器的过程中修改字符编码

php - 如何在我的 View 中回显查询结果?

mysql - 从生成的大型查询中修剪尾部 mysql group_concat

mysql - 使用子查询 select 获取列值

php - 按日期对回复和新话题进行排序

Javascript - 根据字符拆分字符串但将其保留在结果数组中

javascript - 更改时返回选定的值,取消选择时不重复

php - 使用文件系统从 AWS S3 下载的 Laravel 文件已损坏