Jump to content
Stef's Coding Community
makamo66

Undefined index error

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: 
 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...