Why doesn't this code work?
It creates a random number, if it exists in database then it generates a new one until it can insert into the unique key, if not then it inserts straight away into database.
$id;
do {
$id = mt_rand(1, 10);
"SELECT count(*) FROM accounts WHERE id = '$id'";
} while (count != 0);
$sql = "INSERT INTO accounts (id, username, email, password, sex)
VALUES ('$id', '$username', '$email', '$password', '$sex')";
The reason the mt_rand is low for testing purposes.