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!

Refresh Problem w/ SQL Insert

Status
Not open for further replies.

GeeWond3r

IS-IT--Management
Sep 5, 2003
65
US
In my asp page, there are a few sql inserts commands. And the problem is that whenever someone refresh the browser (either F5 or the Refresh button), another record is added to the database. Is there any easy/quick solution to this? I do hate to perform a post Check on every single inserts!
 
Can you perform the inserts on one page then redirect to another page as soon as the Inserts are complete? If the user doesn't stop on the insert page, he'll have a hard time refreshing it.
 
The best way to handle it is by following MoLaker's advice. After your inserts redirect the user. Also you may want to add this code to the top of your insert page so the "Back" button will show that the page has expired. It doesn't however prevent them from refreshing the page.
Code:
<%response.Buffer="true"
  Response.ExpiresAbsolute = #2000-01-01# 
  response.AddHeader "pragma", "no-cache"
  response.AddHeader "cache-control", "private, no-cache, must-revalidate"
%>
Another more complicated way around this is to insert the current Session.ID or another GUID that identifies the user and insert that just occurred. Before you allow any inserts, check to see if a value exists in that column and compare it with the current session id or GUID that you assigned to the user session. If you get a match then redirect them elsewhere explaining that they can only insert data ONCE.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top