i m asking it again so this is more specific.
$cartOutput.='<form method="post" action="cart.php">
<input type="submit"name="deletebtn'.$item_id.'" value="remove"/>
<input type="hidden" name="index_to_remove" value="'.$i.'"</form>';
in this index_to_remove is coming via a hidden input type in the form... i created a form with a remove button and via a hidden output field i passed the index of item that i want to remove from the cart and implemented this code.But its not working.......
<?php
/////////////////////////////////////////////////////////
// if user wants to remove an item from cart
////////////////////////////////////////////////////////
if(isset($_POST['index_to_remove']) && $_POST['index_to_remove']=!"")
{
//access the array and rum code to remove that array index
$key_to_remove=$_POST['index_to_remove'];
if(count($_SESSION['cart_array'])<=1)
{
unset($_SESSION['cart_array']);
sort($_SESSION['cart_array']);
}
else
{
unset($_SESSION["cart_array"][$key_to_remove]);
sort($_SESSION['cart_array']);
echo count($_SESSION['cart_array']);
}
}
?>