Forum Moderators: coopster
<form name="form1" method="post" action="phpcode/update_stock_level.php">
<table width="80%" border="0" class="btn-large">
<tr>
<th scope="col">Stock Item:</th>
<th scope="col">Qnty Received:</th>
<th scope="col">Item Cost:</th>
<th scope="col"> </th>
<th scope="col"> </th>
</tr>
<tr class="phone">
<td><select name="lst_product[]" class="controls" id="product_id">
<option><?php prod_list()?></option>
</select></td>
<td><input name="txt_quantity[]" type="text" class="controls" id="quantity" value=""></td>
<td><input name="txt_item_cost[]" type="text" class="controls" id="item_cost" value=""></td>
<td> </td>
<td> </td>
</tr>
</table>
<p><a href="#" class="copy" rel=".phone">Add stock line</a></p>
<div class="span7"><p>
<input name="updatestock" type="submit" class="btn-primary" id="button" value="Submit">
<span class="textarea">
<input name="hidden_company_id" type="hidden" id="hidden_company_id" value="<?php echo $_SESSION['sess_company_id']?>" />
</span></p>
</div>
</form> echo '<pre>';
print_r($_POST); echo '</pre>'; on the receiving page I get an array like this: Array
(
[lst_product] => Array
(
[0] => 1
)
[txt_quantity] => Array
(
[] => 33
)
[txt_item_cost] => Array
(
[0] => 44
)
[updatestock] => Submit
[hidden_company_id] => 5
) <?php session_start();?>
<?php require_once('../Connections/connpay.php'); ?>
<?php require_once('../functions/global_functions.php'); ?>
<?php require_once('../functions/account_functions.php'); ?>
<?php
//$company_id = ($_POST['hidden_company_id']);
?>
<?php
//Lets connect to the database
if(mysqli_connect_errno()){
exit("Failed to connect to the database".mysqli_connect_error());}
?>
<?php
foreach ($_POST['lst_product'] as $row=>$id)
$productid = $id;
$newquantity = ($_POST['txt_quantity'][$row]);
$query = "UPDATE acc_stock_items SET stock_level = '$newquantity' WHERE product_id = '$productid'";
if($conn->query($query)===TRUE){
echo $company_id;
//Header("Location:../view_stock_items.php");
echo "all good";
echo "quantity is ".$newquantity;
}
else {
echo "Error:".$conn->error;
}
?>
<?php
//$update_stock = array(
//$prodid => $_POST['lst_product'],
//$quantity => $_POST['txt_quantity'],
//$cost => $_POST['txt_item_cost']);
echo '<pre>';
print_r($_POST); echo '</pre>';
echo print_r($_POST);
?>