Code:
<?php
srand ((double) microtime( )*1000000);
$random_number = rand( );
echo "$random_number";
?>
I want to use this random code generator, to store in the database a code. I want this number to be unique. How can I keep PHP from duplicating a code saved in the database?
I can tell MySQL to keep it unique, but I don't want an error page. I want to keep errors to a minimum. Thank you for the help.
I was thinking of a loop to check if it exists until it finds a unique number and end the loop before it spits out the page with the code in a hidden field. I just don't know what codes to use. >_<