You are here: Re: Ensuring a web page refresh doesn't create a new record « PHP SQL « IT news, forums, messages
Re: Ensuring a web page refresh doesn't create a new record

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация