The form is on a different page called product.php. This page is in the same directory as cart.php. cart.php is the file that the $POST, variable $POST['h2'], does not populate. However $_POST[pid'] does populate. Both variables are coming from the same form.
[code]
<form id="form1" name="form1" method="POST" action="cart.php">
<input type="hidden" name="pid" id="pid" value="<?php echo $id;?>"/>
<input type="hidden" name="h2" id="h2" value="pancakes"/>
<input type="submit" name="submit" id="submit" value="Add to Shopping Cart">
</form>[/code]
I've tried this code on the cart.php page and there is nothing in the POST array
<?php
print_r($_POST);
var_dump($_POST);
?>
results:Array ( ) array(0) { }
If I remove this code below from cart.php the variables post to the page.
<?php
if (isset($_POST['pid'])&& !empty($_POST['pid'])){
$pid = $_POST['pid'];
$i=0;
$wasFound = false;
// if not set, or cart array is empty
if (!isset($_SESSION['cart_array']) || count($_SESSION['cart_array'])<1){
$_SESSION['cart_array'] = array( 0 => array('item_id'=>$pid, 'quantity'=> 1));
}else{
// at least one item was found in the cart
foreach($_SESSION ['cart_array'] as $each_item){
$i++;// hold value of which associative array with in mulitdeminalt array is pasing thru loop
while(list($key,$value) = each($each_item)){
//while loop access to al key value pairs in cart_array
//list() Like array(), this is not really a function, but a language construct. list() is used to assign a list of variables in one operation.
//each()Return the current key and value pair from an array and advance the array cursor.
if($key == "item_id" && $value ==$pid){
// that item is in cart already so lets adjust it quanity using araay_splice();
// add one to that item
///array_splice remove portion of array and replace it with someting else
//input, offset, index, replacemnt
array_splice($_SESSION['cart_array'], $i-1, 1, array(array("item_id" =>$pid, "quantity"=> $each_item['quantity'] +1)));
$wasFound =true;
}
}
}
if($wasFound == false){
array_push($_SESSION['cart_array'], array('item_id'=>$pid, 'quantity'=> 1));
print_r($_SESSION['cart_array']);
}
}
header("location:cart.php");
exit();
}
?>