duplicate key blocker script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cap2cap10
Forum Contributor
Posts: 158
Joined: Mon Apr 14, 2008 11:06 pm

duplicate key blocker script

Post 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
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: duplicate key blocker script

Post 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.
Post Reply