Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts

    Unset() not working as expected - where SHOULD I be putting it.

    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?
    PHP Code:
    if(isset($_POST['eml'])){
        
    $email=mysql_real_escape_string($_POST['eml']);  //  capture the cleaned data
        
    unset($_POST['eml']);  //  clean slate
        
    if(validEmail($email)){
            
    $sql="INSERT INTO `Optout` (`emailAddress`) VALUES (\"$email\")";
            
    $succesful=mysql_query($sql);
            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>"
    ;
                unset(
    $email);
            }else{
                echo
    'Insert Statement Failed: '.mysql_error();
                unset(
    $email);
                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).
    PHP Code:
    $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" />    
    </form>'

    Last edited by mOrloff; 02-24-2010 at 08:45 PM.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,395
    Thanks
    13
    Thanked 353 Times in 349 Posts
    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"?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Regular Coder mOrloff's Avatar
    Join Date
    Nov 2008
    Location
    The Great Pacific NW, USA
    Posts
    424
    Thanks
    8
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by Dormilich View Post
    ... refreshing means submitting the form again ...
    AHAH!
    It looks like I'm smarter than myself
    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.

    Quote Originally Posted by Dormilich View Post
    ... what happens, if you dump $_POST after unsetting "eml"?
    POST is empty.

    Thanks-a-bunch.
    ~ Mo


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •