[英]Can't get form based off mysql query to load all POST variables
Trying to create form from a mysql query where I can update a field on each row. 尝试从mysql查询创建表单,在此我可以更新每一行的字段。 However it's only POSTing my last row. 但是,这只是发布我的最后一行。 Here is what I have. 这就是我所拥有的。
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>
Form displays 3 rows. 窗体显示3行。
1 cheerwine each 33 ____ .38 每个33 ____ .38 1
2 cool blue each 11 ____ .66 每个2个凉爽的蓝色11 ____ .66
3 diet peps each 13 ____ .51 每组3次减肥小食13 ____ .51
Each row I enter new_quantity_on_hand with a number 1 less than old_quantity
. 我输入的每行new_quantity_on_hand都比old_quantity
小1。
So I have 3 rows that should post with the numbers 32, 10 and 12 where the underscore is, but only the last row posts. 因此,我有3行应该用下划线所在的数字32、10和12发布,但只有最后一行发布。
Output is: 输出为:
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++;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.