Click to See Complete Forum and Search --> : Refresh page causes a re-submittance to DB


pedellen1000
09-17-2005, 08:06 AM
Hi,

I just made a PHP script which add some stuff to a database, but when Its done and I hit the reload button on the browser, the same stuff is once again added to the DB, causing it to store the same variables twice?

Anything which can be dont to avoid that the script on refresh submits once again?

I've tried to change my $_POST variables and to set up an if-statement which check to see if a variable is 0 or 1, and if 1 = add stuff to db (and change the current $_POST var to 0) else do nothing. But still on reload is adds stuff to my DB?

Cheers,

Mads :D

phpstuck
09-17-2005, 08:20 AM
Just choose a field that is unique (IE: in the case below it is an example of a dictionary, WORD should only be in the dictionary one time so I use that as a base to check for duplicates)

Hope this helps.

$sql_word_check = mysql_query("SELECT word FROM define
WHERE word='$word'");

$word_check = mysql_num_rows($sql_word_check);

if(($word_check > 0)){
echo "<center><b><font face='tahoma' color='red'>Please fix the following errors: </b><br />";
if($word_check > 0){
echo "The word you have submitted has already been defined in our database.
Please submit a different word or phrase!<br />";

unset($word);
}