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!

Prevent db update on page reload 1

Status
Not open for further replies.

kunai

Programmer
Jun 4, 2004
52
CA
Hi,

Is there a way to detect when a page is reloaded or prevent a database update on a page reload?

I have 2 pages, page1.cfm and page2.cfm.

page1 submits to page2 and page2 updates the database and displays some information.
I want to prevent page2 from inserting data in the db again when F5 or the Refresh button is pressed.

The only solution i found was to have the processing in a separate file, i.e. page1 -> processingPage -> page2.
I'd like to avoid that coz that'd be a huge modification.

Thanks!
 
one approach (and there are several, but this one is the best, in my opinion) is to ensure that the database table has a unique constraint defined, so that it is not possible to insert the same data again

r937.com | rudy.ca
 
This right here is your problem.

"page1 submits to page2 and page2 updates the database and displays some information."

You are updating the Database and displaying the page with the same template. You have to separate both, Processing is one thing and displaying the info another.

Also when submitting from form1 make sure you have a POST not a GET and do not cache the page. That way is somebody wants to go back to Form1 then a new page is loaded erasing the previous entries, similar to how your bank account works.

Lastly, it may a huge modification now, but if you implement
a processing page then you'll rip the benefits in the future. Is going to be a major headache if not addressed, you may as well go through all the pain now.


grtfercho çB^]\..
"Imagination is more important than Knowledge" A. Einstein
-----------------------------------------------
 
there is really no need to split the cfm module into three (form, action, display)

all can be handled within the same module if you observe some simple programming techniques (e.g. detect the submit button)

a form that submits to itself is very common

furthermore, this makes it easy to keep the form field values if an error must be displayed

there's nothing worse for a user than filling in a form, pressing submit, getting an error, and then having to fill all the fields in again

with separate modules, the action module then has to send control back to the form, and how do the values get passed back? usually with hidden fields

that's way more trouble than just designing the form to submit to itself

just my experience, and i'm still a coldfusion novice



r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top