I am trying to create a username for my website based on their first name and their last name. (FirstName.LastName) If a person has the same first name and last name then they would have the same username. I am trying to make it so that if they do have the same name it would just add an incrementing number. Here is what I have so far.
$sq = "SELECT * FROM Users";
$quer = mysqli_query($conn, $sq);
$userName = '';
$mod = 1;
$foundUser = false;
while ($row = mysqli_fetch_array($quer)){
if($row['UserName'] == ucfirst(strtolower($_POST['fName'])) . '.' . ucfirst(strtolower($_POST['lName']))){
while($foundUser = false){
if($row['UserName'] == ucfirst(strtolower($_POST['fName'])) . '.' . ucfirst(strtolower($_POST['lName'])) . $mod){
$mod = $mod + 1;
echo 'hitting mod';
}else{
$userName = ucfirst(strtolower($_POST['fName'])) . '.' . ucfirst(strtolower($_POST['lName'])) . $mod;
$foundUser = true;
echo 'last else';
}
}
}
}
This isn't currently populating the $userName variable and I don't know why. I have a while loop. None of the echos are being hit which is weird. There is definitely multiple users with the same username already in my table.