Dear all,
Last time when i posted my problem in phptalk, i found the solution instantly. This time also i am hopeful!
I want to store the values typed in the text boxes in mysql database, that is not a problem, Once the data is stored in database and some message displays then when i refresh the page, same data get inserted time and again.
how to avoid it?
Thanks
Posting form values
Started by dahal0514, Aug 08 2010 09:28 AM
1 reply to this topic
#1
Posted 08 August 2010 - 09:28 AM
#2
Posted 08 August 2010 - 12:43 PM
Hi dahal0514,
When you refresh a page that has been POST'ed to, that POST data is re-submitted. Most browsers will also warn about this.
To avoid the data being inserted twice in cases like that, you could add a check in your code to query the database and abort if some value (that is supposed to be unique) already exists.
If you do not have any values that are supposed to be unique, you can most likely avoid the problem by (after form submission/processing) redirecting the user to a new page where the status message is displayed. You can for an example pass a status code via GET when you redirect the user to for an example your index page - and have a mechanism there that checks for such a status code, and displays the appropriate status message somewhere on the page (e.g. in a formatted box above the content). Alternatively, if you do not want to pass anything via the URL, you could also use a $_SESSION variable (if you are using sessions) to pass data between pages (and unset it once displayed). As a 3rd option, it would also be possible to use the database as a temporary storage for status messages.. and delete them once displayed.
- S.
When you refresh a page that has been POST'ed to, that POST data is re-submitted. Most browsers will also warn about this.
To avoid the data being inserted twice in cases like that, you could add a check in your code to query the database and abort if some value (that is supposed to be unique) already exists.
If you do not have any values that are supposed to be unique, you can most likely avoid the problem by (after form submission/processing) redirecting the user to a new page where the status message is displayed. You can for an example pass a status code via GET when you redirect the user to for an example your index page - and have a mechanism there that checks for such a status code, and displays the appropriate status message somewhere on the page (e.g. in a formatted box above the content). Alternatively, if you do not want to pass anything via the URL, you could also use a $_SESSION variable (if you are using sessions) to pass data between pages (and unset it once displayed). As a 3rd option, it would also be possible to use the database as a temporary storage for status messages.. and delete them once displayed.
- S.
Hi there! If you found this post useful, or used this information to help others, we would greatly appreciate a link back to our forum from your website/blog. Thanks! =)
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












