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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

refresh problem 3

Status
Not open for further replies.

mrtopher

Programmer
Joined
Aug 27, 2003
Messages
34
Location
US
I have written a program, when someone enters information into a form it is them entered into a database if all of the validation works out. The issue is, if the user refreshes the results page, a duplicate entry is recorded into my database. I have tried emptying the variables after the results are printed but that doesnt work.

Is there a way that I can keep the duplicate entry from being recorded into my database if the page is refreshed?
 
Hi,
What u can do is to redirect the user to a different page after u r done with the database interaction.

Code:
<?
..validation..
..insert the record..
header(&quot;Location:thankyou.php&quot;) ;
?>
so even if the user refreshes the page its that thank you page and the data will not be gtting inserted again.


--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Spookie's option is a great one... the only downside is now the back button becomes a problem, personally I've used it in sites where I trust my users not to be dolts, but when they may be dolts, I go to session variables.

Basically, at the top of my form page where they're filling things out I say...

Code:
session_start();
$_SESSION['submitted_to_db'] = false;
blah
blah
...

and then my submission page looks like

session_start();
if ($_SESSION['submitted_to_db']) {
  echo &quot;Stop hitting refresh you loon<br />&quot;;
} else {
  $_SESSION['submitted_to_db'] = true;
  ... code to submit it to the db ...
  ... and any other things I want to do ...
}

-Rob
 
It is, as spookie says, probably not a good idea to 'trust' visitors. Don't rely on their intelligence or good will.
If you don't use session variables you also open your application to an attack with automated submissions, flooding your system with new - and identical - records.

I'd consider to implement sessions. It's easy and a great way to solve the problem.
 
Absolutely!!

A star to skiflyer.

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top