Click to See Complete Forum and Search --> : how to avoid this
I have created 2 programs called as form1.html and add.asp
In form1.html, the customer will enter his name, age, address, gender etc and when he clicks submit button, the browser will be redirected to
add.asp
In add.asp, I retreive the form1.html elements through request.form
and I have written 'Insert Sql query' to insert into mssql database.
But the main problem is, suppose my customer presses F5 key or presses refresh button in add.asp, then the same set of records get added to the database. That is duplicate records are added to database.
So how to avoid adding this, when customer presses F5 or refresh button.
Regards.
Two ways...
1) Check (by using SQL) that you don't have the same record in your database twice (u need to do it anyway). If you do, show the right message. If not, enter the record.
2) easier, create a "Thank You" page with the right message and once you entered the details, redirect to this page. Pressing F5 in this page will 'cause... nothing.
Good luck!
minority
07-29-2005, 03:01 AM
after you have used your sql place this code bellow it.
Response.Redirect("thank.asp")
in the brackets pretty much any web page you want to redirect to
if you want to do the thank you page as Wee suggested you could redirect to it (Preventing them hitting f5) and then have a timed thank you page so if they dont click on something it automatically takes them back to the index.asp
The code for doing this is pretty simple simply add this between your <head></head> tags
<meta http-equiv="refresh" Content="5; URL=index.asp"> the 5 is the number of seconds until it does an auto redirect you could also use this in the add.asp page if you choose but you could still fall pray to refresh
I have heard something like
response.cachecontrol=nocache
response.expires=-1
how can this be used in insert page, so that after pressing F5 or refresh button, duplicates are avoided
Regards.
I donnow about that but I do know that you HAVE to make sure you don't have the same details in your database anyway.
Doesn't it make sense?
minority
07-29-2005, 04:58 AM
do you mean this
note: from imf232s
Response.CacheControl = "no-Cache"
Response.AddHeader "Pragma" , "no-cache"
Response.ExpiresAbsolute = Now() -1
this should prevent there system from caching the pages so when they click the back button etc it should refresh without using the cache but not sure if it will destroy varables??
Also if you do use that and they hit refresh then they will prob error out as there nothing to update/insert or you could end up with null entries i imagine.
Adamal
08-03-2005, 05:14 PM
Please see this related thread for more info:
http://www.webdeveloper.com/forum/showthread.php?t=74320
~Adamal