Jump to content

Undefined index error


makamo66

Recommended Posts

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: 
 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.