refreshing webbrowser re-inserts data in database
Posted 01 March 2006 - 03:51 PM
When I submit the form I check the submitted data with a self-written php-validator-class. When the validator-class says that there are no errors I insert the data in the database using a self-written php-DBFactory-class and the datatable on the webpage is updated with the new data.
When the validator-class says that there are errors, the page does not write to the database, but instead showes the errors.
This all workes fine. But my problem now is that when I submit the data and the data gets written to the database, and I than click refresh on the webbrowser, the data gets written a second time to the database and the datatable on the webpage also gets reloaded with the new data (the new data is inserted twice).
So the data from the POST is re-used when I refresh the webbrowser.
How can I solve this refresh-problem?
I heard about something like having a processing-step in between pages that makes sure that when you submit your form, a "new" page gets shown so that on refresh, the POST-data is not there anymore.
But I wouldn't know how to do this.
Does anybody have an idea?
Posted 01 March 2006 - 04:02 PM
header("Location: " . $url);
Now url shold be another script that will display whether the query was completed or not.
as part of url u can pass paramters so that this script can display messages and possible links like so...
$url = "message.php?mssg=succes&back=form.php&next=index.php";
you can then do anything with those parameters in the new script and if you hit refresh it won't execute teh query again.
Posted 01 March 2006 - 04:17 PM
I had seen the "header"-solution on many webpages, but the warning I always get with that solution is
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: Cannot modify header information - headers already sent by ...[/quote]
So my guess is that there should be kind of a solution where you have your form-page, witch after validation, forwards to a "control-page of some sort" witch inserts the data and redirects to the page where you inserted the data, but with the new data and the same form showing.
Posted 01 March 2006 - 04:23 PM
Now as you want to prevent this refresh problem, using the header to change the page after processing the data means that you no longer need to output any html in the script that does the insert/edit/delete form teh database. Therefore you won't get that error!
Posted 01 March 2006 - 04:37 PM
So my data flow is something like this :
Page 1 - Enter Data and click Submit
Page 2 - Handle the data and forward to page 3
Page 3 - Display the data how I want it
There's additional power here too.. You can redirect to an error page if there's something wrong with the input, redirect to a multitude of different pages based on the input, etc.
[a href=\"http://blog.godshell.com\" target=\"_blank\"]XenoPhage[/a]
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Something mysterious is formed, born in the silent void. Waiting alone and unmoving, it is at once still and yet in constant motion. It is the source of all programs. I do not know its name, so I will call it the Tao of Programming.[/quote]
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users