Try this little test. Make sure there is more than one id in the session when you do it. Consider this remove.php. This should do all the debugging, and I just tested it, and everything was fine for me.
If you had the three id's like shown above, then this should work for you...
<?php
session_start();
if(isset($_SESSION['products'])) {
echo "<pre>";
print_r($_SESSION['products']);
echo "<pre><br />";
}
else {
die("The products session does not exist");
}
/*
If all is good at this point, your output should look like this:
Array
(
[id1] => product1
[id2] => product2
[id3] => product3
)
*/
if(isset($_GET['proid'])) {
$del = $_GET['proid'];
if(isset($_SESSION['products'][$del])) {
unset($_SESSION['products'][$del]);
if(!isset($_SESSION['products'][$del])) {
echo "<b>".$del." deleted successfully</b><br /><br />Remaining session array:<br />";
print_r($_SESSION['products']);
/*
This is where you want to be,
and your output should look like this:
Array
(
[id1] => product1
[id3] => product3
)
*/
}
else {
die("Could not delete ".$del);
}
}
else {
die($del." does not exist in session array");
}
}
else {
die("No id specified to delete");
}
?>
For my test, I preset these variables:
$_SESSION['products'] = array('id1' => "product1",
'id2' => "product2",
'id3' => "product3");
$_GET['proid'] = "id2";
All went well, so my page looked like this:
Array
(
[id1] => product1
[id2] => product2
[id3] => product3
)
id2 deleted successfully
Remaining session array:
Array
(
[id1] => product1
[id3] => product3
)