tags:

views:

53

answers:

1

data lost when passing session to array and using foreach(looping). qty lost is the text from another page why lost this???? using looping to delete item by id from get (using link in another page)

$cart = $_SESSION['cart'];

$id = $_GET['id'];

$arrcart = array();

$count=0;
    $qty = intval($_POST['product_'.$product['product_id']]);

if($id)
{
foreach($cart as $keys)
{
if($id != $keys['product_id'])
{
        $arrcart[$count]=array('qty' => $qty,
                            'product_id' => $keys['product_id'],    
                            "name" => $keys['name'], 
                            "description" => $keys['description'],
                            "price" => $keys['price'],
                            "total" => $keys['price']*$qty
                            );
}
        $count++;
}`enter code here`
$_SESSION['cart']=$arrcart;
}
</code>
A: 

Looking at your code and taking a stab in the dark, I don't see session_start() anywhere. Try putting this at the top of your PHP code:

session_start();
mattbasta