View Full Version : Unset() not working as expected - where SHOULD I be putting it.

02-24-2010, 09:37 PM
I am building an Opt Out form, and despite my efforts to unset it, the $_POST element keeps persisting.
As you can see on the third line below, I am unsetting it, but if I refresh the page, the if(isset($_POST['eml'])) continues to succeed.
What am i doing wrong?

$email=mysql_real_escape_string($_POST['eml']); // capture the cleaned data
unset($_POST['eml']); // clean slate
$sql="INSERT INTO `Optout` (`emailAddress`) VALUES (\"$email\")";
if ($succesful){
echo "We are sorry to see you go.<br>Thank you for visiting.<br>
<br>$email has been added to the unsubscribe list.<br>";
echo'Insert Statement Failed: '.mysql_error();
echo $form;
} // end IF($succesful)
}else{ // not validEmail($email)
echo $form;
} // end IF/ELSE(validEmail($_POST['eml']))
}else{ // not isset($_POST['eml'])
echo $form;
} // end IF/ELSE(isset($_POST['eml'])&&validEmail($_POST['eml']))

FYI: this is the form (the form page posts to itself).

$form='<form name="optout" action="/optout.php" method="post">
eMail Address: <input type="text" name="eml" />
<!-- TODO: insert recaptcha here -->
<input type="submit" value="Submit" />

02-24-2010, 09:49 PM
if refreshing means submitting the form again (which happens when you reload a page, where you just submitted a form from), then obviously $_POST['eml'] will be created again.

what happens, if you dump $_POST after unsetting "eml"?

02-24-2010, 10:18 PM
... refreshing means submitting the form again ...
AHAH! :)
It looks like I'm smarter than myself :D
When I started this page on Monday, I also used a SESSION cookie to determine the stage of the submition, but today it seemed redundant, so I REM'd it.
I'll reactivate that and see how it works.

... what happens, if you dump $_POST after unsetting "eml"?
POST is empty.

~ Mo