I need to make a key generator, and I need to check from the database that that key does not exist. If the key already exists, I want to generate another key and check if that one exists, until I get one that does not exist. This is what I have, and it's not returning anything if it exists.
function checkHash($hash) {
include 'config.php'; //This calls for the DB
$checkhash = "SELECT * FROM orders WHERE uuid='$hash'";
$resultcheck = mysqli_query($db, $checkhash);
if(mysqli_num_rows($resultcheck) == 0) {
return $hash;
} else {
$orderhash = generateRandomString("15"); //The function that generates the key is generateRandomString();
checkHash($orderhash); //This re-runs the check function with a new key
}
echo generateRandomString("15"); //The 15 means how many characters in the key