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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    102
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to unset $_POST

    HI
    I want when the user submit the form and the query execute successfully the information in the $_POST delete and unset because if the user refresh the page the query execute once again and make another similar row in the database so I want when the query execute the information delete.I user unset($_POST) but it doesn't make doofrence.How can i fix this problem?

    Thanks

  • #2
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    Carn't you do this? $_POST = array();

  • #3
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    You cannot unset $_POST in this case after the form submission. It sounds like the form processor to also acting as the landing page. So unsetting $_POST is useless because on refresh it will be re-populated.

    What I'd recommend it redirecting to a landing page. This will make the request method GET and thus not re-submit the form when refreshed:
    PHP Code:
    /* - - - - - - - - - -
     * Was the form submitted?
     */

    if ( 'POST' == $_SERVER['REQUEST_METHOD'] && ! empty( $_POST ) )
    {

        
    $errors = array();

        
    /* - - - - - - - - - -
         * Do your $_POST processing stuff
         */

        
    if ( ! isset( $_POST['name'] ) || '' == trim$_POST['name'] ) )
        {
            
    $errors['name'] = 'Not a valid name';
        }

        
    /* - - - - - - - - - -
         * No errors?
         */

        
    if ( empty( $errors ) )
        {
            
    header'Location: /thank-you.html' );
            exit;
        }



  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Or use SESSION and store a variable after database insert and check for this value when reloading the page.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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