...

View Full Version : How to unset $_POST



hno2005
10-25-2009, 08:27 AM
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

Lee Stevens
10-25-2009, 11:32 AM
Carn't you do this? $_POST = array();

kbluhm
10-25-2009, 06:04 PM
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:


/* - - - - - - - - - -
* 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;
}

}

abduraooft
10-25-2009, 06:13 PM
Or use SESSION and store a variable after database insert and check for this value when reloading the page.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum