$SESSION["cart"][] = $POST["itemid"];
this will number like this
$SESSION["cart"][0] = $POST["itemid"];
$SESSION["cart"][1] = $POST["itemid"];
$SESSION["cart"][2] = $POST["itemid"];
So the key, name of variable, will not have $itemid.
To make the name of variable have $itemid
you use,
add_item.php
<?php
session_start();
/* I do not know what this does
If n=0 then make it empty, does not make sense to me
In order to count an array, it has to exist
and if number of things in this array is = 0
then it is already an empty array = array()
if (count($_SESSION["cart"]) < 1) {
$_SESSION["cart"] = array();
} */
// i might use this, if this what you want
// if there is no such array, make one empty
if ( !isset( $_SESSION["cart"] ) ) {
$_SESSION["cart"] = array();
}
$id = $_POST["itemid"];
$_SESSION["cart"][$id] = $id;
header("location:cart.php");
?>
Then deleting would work
<form id="id" name="id" method="post" action="/remove_item.php">
<input name="id" type="hidden" id="id" value="<?php echo $info['id']; ?>" />
<input name="Submit" type="submit" class="formbox" value="Remove" />
</form>
i changed to this line:
<input name="id" type="hidden" id="id" value="<?php echo $info['id']; ?>" />
... and this to do it, remove_item.php
<?php
session_start(); // MUST BE, in any page using $_SESSION
$id=$_POST['id'];
unset($_SESSION['cart'][$id]);
header("location:cart.php");
?>