mindwarp wrote:
Hi,
When a user submits / posts data my php script Inserts data into my
database.
If they refresh the script or click back and click submit again I get
duplicate record.
Is there an easy solution to this?
Or do I need to create a hidden field which contains some sort of
unquie data, like a time stamp and have a have a unique field which
stops it adding the record?
Best regards,
Jules.
You could for instance:
a) test the values received against the database before inserting, i.e.
do a SELECT count(*) FROM table WHERE field1=$_POST[field1] AND
field2=$_POST[field2] ...
If the count if 1 or more, give an error message to the user and don't
insert.
b) make one or a combination of fields in your table unique which should
make the insert fail. Be careful which combination you choose.
Having a unique field in your table is always a good idea. Normally this
would be a record-id field which auto-increments. This however will not
prevent duplicate records from being entered as each record gets a new
unique auto-incremented id.
Having a timestamp as a unique field does not sound like a good idea.
What about two users opening the same form page at the exact same moment
? (depending on how busy your site is, probably a very rare occurance,
but still)
It could work if your site does not have large volumes of traffic, but
it is not a stable solution.
Good luck,
Juliette