Beauford Posted January 27, 2008 Share Posted January 27, 2008 I have a form that users enter info into and then it's put into a mysql database. How do I clear the variables so that the user can not hit refresh on their browser and add another record. I've tried unset($var) or unset($_POST), but I must be missing something on what unset actually does as all the variables are still there when refresh is used. I am using the same page for everything. I know I could use a seperate page, but it is all done this way now and I don't want to have to change everything. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/88002-unset-question-or-something-to-clear-variables/ Share on other sites More sharing options...
laffin Posted January 27, 2008 Share Posted January 27, 2008 nope $_POST is sent by the browser someone hits refresh $_POST is resent by the browser so dun matter what yer script does. u have to setup an external variable, somehow. either by cookies, sessions, file or a db field. Quote Link to comment https://forums.phpfreaks.com/topic/88002-unset-question-or-something-to-clear-variables/#findComment-450241 Share on other sites More sharing options...
themistral Posted January 27, 2008 Share Posted January 27, 2008 You could use <?php // your form action here header('Location:your_page.php'); ?> to redirect the page after the form processing - this will then lose the $_POST variables. the header will only run as long as you are not echoing anything to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/88002-unset-question-or-something-to-clear-variables/#findComment-450383 Share on other sites More sharing options...
Beauford Posted January 27, 2008 Author Share Posted January 27, 2008 You could use <?php // your form action here header('Location:your_page.php'); ?> to redirect the page after the form processing - this will then lose the $_POST variables. the header will only run as long as you are not echoing anything to the browser. Then as I figured, you get the dreaded: Warning: Cannot modify header information - headers already sent by (output started at ..............\rdr\rdr_registration.php:160) in ............\rdr\rdr_registration.php on line 272 Quote Link to comment https://forums.phpfreaks.com/topic/88002-unset-question-or-something-to-clear-variables/#findComment-450466 Share on other sites More sharing options...
Beauford Posted January 27, 2008 Author Share Posted January 27, 2008 So the question is then, how do I do this? Basically I have a form that gets filled out. After it is filled out and the user submits it I want to display a message that says, Thanks Bob, you are now registered and your ID is AAAAAABBB. I have it working fine using one page, but then I get my original problem of the user hitting refresh and adding the record again. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/88002-unset-question-or-something-to-clear-variables/#findComment-450489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.