Page 1 of 1

duplicate key blocker script

Posted: Thu Jun 09, 2011 9:57 pm
by cap2cap10
Hello again members of the php Technorati. This time I come seeking you wisdom on a script I am trying to create. Duplicate key entries are rare but do occur and can stop the form process in its tracks. I wrote a simple script to block this from occuring; I am aware of unique keys, but again it will stop the form process. Here is my script:

Code: Select all

$new_ID = rand(0000000000, 9999999999);
 $login = mysql_query("SELECT ID FROM login")
or die(mysql_error());
$ID_array = mysql_fetch_array( $login );
  If (new_ID == $ID_array['ID']){
 $new_ID2 = rand(0000000000, 9999999999);
 $new_ID2 = $ID;
}else{
 $new_ID = $ID;
}
I would appreciate any input you have.
Thanks in advance,

Batoe

Re: duplicate key blocker script

Posted: Fri Jun 10, 2011 12:43 am
by flying_circus
Why not just specify your database field as unique and flag it as auto-increment? This would require no PHP, it's all done at the SQL server.