Click to See Complete Forum and Search --> : browser refresh and duplicate data


MayaPT
09-12-2005, 01:19 PM
Hi everyone,

This might be a really easy issue, but it's driving me mad. I have some kind of form and i'm using the data on that form to insert data into a mysql database. Now my problem is that after selecting the save data button if someone presses F5 or refreshes the browser in any other way, the data gets duplicated, is there any way of preventing this or any ideas on how to control this stuff?

thanks to all in advance for your time and help.

cheers

madddidley
09-12-2005, 01:32 PM
I don't think so but I'm not 100% sure.


www.maddDidley.com

chazzy
09-12-2005, 01:59 PM
Are you using gets or posts?
You could force them to go to a different page after its done running.
IE:
Go to form, submit
Go to processing page, insert,
after insert go to display page.

NogDog
09-12-2005, 02:47 PM
Add a hidden field to the form with a unique value (such as can be generated via the uniqid() function). Add a "transaction_id" or similar column with the UNIQUE attribute to your data table to save that ID when a record is inserted. You can check that the transaction ID does not exist in the table before doing an insert, or just let MySQL generate an error if you try to insert a record with an already-used transaction ID.

MayaPT
09-12-2005, 07:04 PM
Hi everyone and thanks for your replies.

chazzy:

i'm currently using POST as the method for the form submit

NogDog:

you're solution is a possible one but let me elaborate a little more on what i'm doing, maybe i'm doing it all wrong.

i'm working on some kind of backoffice or backend system that will allow someone to insert news and stuff into an interface and then that data will become available on some page automatically. so i use the same form only changing the action field that will determine the action to be taken after the submit. the problem is not when i'm using the interface because after issuing a insert action i change the action to edit or something like that, the problem is that by pressing F5 the browser refreshes with the exact same form data, so there's no way i can control the way it will react to that. ofcourse the data has id, but i'm letting mysql assign that automatically so at runtime i don't have anyway of knowing it before i insert it in.


Any more ideas and /or comments on this situation is appreciated. Thanks and cheers.

SpectreReturns
09-12-2005, 08:50 PM
I think you missed NogDog's point. Make a unqiue field in MySql, which makes MySql ignore anything with the same unique data. Then, in the GUI before this, generate a uniqueid as a hidden value, and use that as your unique data.