How do I get my session to be unset?
My form looks like this:
foreach ($joined as $i => $qty){
echo "<form action='' method='get' name='yourForm'>";
echo "<button type='submit' name='remove_" . $i . "' value='remove_" . $i . "' class='deletebtn' >X</button>";
echo "</form>";
}
My SESSION is defined like this:
for($i=0; $i<=5; $i++){
if (isset($_REQUEST["element_id_$i"]) ) {
$_SESSION["element_id_$i"] = $_REQUEST["element_id_$i"];
$id = $_SESSION["element_id_$i"];
array_push($_SESSION["element_id"],$id);
}
$id = $_SESSION["element_id"];
}
and the form submits to:
if (isset($_REQUEST["remove_$i"]) ){
unset($_SESSION["quantity[$i]"]);
unset($_SESSION["element_id[$i]"]);
var_dump($_SESSION["element_id"]);
var_dump($_SESSION["quantity"]);
echo "Received variable " . $_REQUEST["remove_$i"];
echo 'TARGET INDEX TO BE REMOVED: ' . $_SESSION["element_id[$i]"] . '<br><br>';
}
The output is:
array(1) { [0]=> string(1) “1” } array(1) { [0]=> string(1) “1” } Received variable remove_1
Notice: Undefined index: element_id[1] in C:\xampp\htdocs\TopView\cart5.php on line 147
TARGET INDEX TO BE REMOVED: