I have searched high and low for an answer with no avail.
I am trying to insert a random id number for my users between 9999,99999999. Problem is they have to be unique. I have everything set up but with an auto increment set for the id. I figured I will keep the auto increment field and just add another row for the unique id.
This is what I got so far:
$id = mt_rand(9999,99999999);
$query = "SELECT * FROM accounts";
$result = mysql_query($query) or die(mysql_error());
while($account = mysql_fetch_array($result)){
if ($id == $account['id']){
$id = mt_rand(9999,99999999);
} else {
$sql = "INSERT INTO accounts (id, username, email, password, sex)
VALUES ('$id', '$username', '$email', '$password', '$sex')";
mysql_query($sql);}}
Now I figured if I create a random number, check the database if it exists create another, else insert it, but it is not working, if it a simple solution I apologise.
Thanks again :)