So, I have written a function which checks my database to see if the username is already taken.
Basically, it is always returning 1 for the amount of rows, even if the variable $user is not a username in the database.
Not sure why, any ideas?
Function:
function userTaken($user){
require_once('db.php');
$taken = mysqli_query($mysqli, "SELECT * FROM users WHERE username = '$user'");
if (!$taken) {
die(mysqli_error($mysqli));
}
$cnt = mysqli_num_rows($taken);
if($cnt > 0){
return true;
} else {
return false;
}
}
Calling Function:
if(userTaken($user)){
echo "<font color='red'>That username is already taken!</font>";
}