Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stopping the re-running of a script 1

Status
Not open for further replies.

smashing

Programmer
Oct 15, 2002
170
US
Hi There!
I have a form for a bus company reservation system that takes personal info & submits it to a PHP script . If all the necessary criteria is met the script runs and the information is added to the system. Problem is that if the refresh button is pressed the script will run again, thus resulting in a duplicate reservation. How can I prevent this from happening?

An idle mind is the Devil's workshop!
 
One way:

The script that produces the form sets a session variable called "new_input" and sets it to 1.

The script that processes the input checks that variable. If the value is not 1, it does not process the data. If the value is 1, it processes the data and sets the variable to some value other than 1. Want the best answers? Ask the best questions: TANSTAAFL!
 
Thanks for the reply. One script does both. It first processes the form, then if everything is fine it goes on to produce HTML output at the end. I'm new to PHP & don't know much about session variables yet (If you're refering to the $_SESSION superglobal), but if I have to learn it I will. Meanwhile I tried putting a hidden field called fielda in the form with a value of 1. Then in the script I had :
$check = ($_POST[fielda]);
$check++;
if ($check > 2) {
echo "BANG!";
exit;
}

This doesn't help because the value of $counternever gets above
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top