|
Posted by Stefan Rybacki on 11/18/05 19:58
Sam wrote:
> Hi,
>
> Another question:
>
> As per my previous post, my database is very simple: User ID, Country,
> Postcode and Date.
>
> This information is entered through the browser via a standard form
> which works well.
>
> Problem: If the user clicks on the browser's refresh button, the same
> data gets added to my SQL database as a new record. Everytime refresh
> is hit, a new record is added with the same data.
>
> What's the best way to prevent this from happening?
>
> I know you can set fields as being unique in MySQL, but can you set -
> say - an entire row? So another duplicate row containing all of the
> same values could not be written? This would be sufficient for my
> needs!
This is what Unique indices do. You could also use replace statements if you have unique
or primary key values. Replace is similar to insert except that it updates a row if
another row with the given primary key or unique value already exists.
Another way is to store whether you already saved the record. Or use an additional script
like this:
Input -- script call --> insert.php -- redirect --> result page
This way refreshing would only refresh the result page and not the insert script.
Regards
Stefan
>
> Thanks in advance!
>
> Sam Day.
>
Navigation:
[Reply to this message]
|