All,
I'm writing a script that does the following, takes user sign-up information and stores it in a database, then e-mails the user a welcome e-mail with account summary information. This part works great.
What I need to do is generate a random 10-digit number that will be assigned to each user at the time of sign-up. Generating the number is easy enough.
$number = rand(000000001, 9999999999);
My problem is after the number is generated I need to query the database to see if the number is already assigned. Now I know the likelihood of a duplicate number being generated with the parameters I'm using is microscopic but I still have to make 100% certain that a duplicate number is not assigned. If by chance the number is already assigned I need it to go back and generate a new number before inserting it into the db with the rest of the data. What's the best way to go about this?
TIA