Problem with PHP $_POST

I've started to have an odd problem with PHP. I have a PHP page that can be submitted in three different ways to determine what data base processing will occur:
1. By just entering the URL in the browser address, or refreshing, with no query string (should set no $_POST or $_GET variables).
2. By entering the URL with a query string (should set $_GET variables only).
3. By clicking a Submit button in one of two forms on the page with "action=page url" and "method=post" (should set $_POST variables from form only).

What's happening is that after I invoke the page using method 3 and update the data base, then refresh the page which should imply method 1, the previous $_POST variables are kept, and $_SERVER["REQUEST_METHOD"] is still set to "POST".

Is there a way to correct this so all $_GET or $_POST variables are cleared when I refresh the page?
 

MarkR

New Member
When you refresh a page the browser will resubmit the form (all your post variables) automatically, this can't be changed.

Workarounds are:

- Storing a session variable unique to the form so you can tell if the form has been submitted more than once.

- Taking the user away from the form when they submit it so a refresh there will not resubmit variables.
 
I like your answer Mark. This is the exact problem i have been facing. When i click the refresh button, the else part of my if statement appears on the screen even when the form wasnt filled. I will try out your solution and let you know. Thanks Mark.
 

SamuelV

New Member
3. By clicking a Submit button in one of two forms on the page with "action=page url" and "method=post" (should set $_POST variables from form only).

or in action type action="save_database.php" and when press submit it will be redirect to a new page and after work with information redirect to current page. and when you will refresh form will not be resubmited
 
Last edited:
Top