So I'm using this code to check if a username exists in a database.
$sql = $db->query("SELECT FROM people (username, password, email) WHERE username=$username");
if(mysql_num_rows($sql)>=1)
{
echo"name already exists";
}
else
{
$sqll = $db->query("INSERT INTO people (username, password, created, ip) VALUES ('{$username}','{$ph}',NOW(),'{$ip}' )") or die("Error creating user");
}
But when I run it I get
( ! ) Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /Users/idrisk/Desktop/localhost/r.php on line 17
I'm not really sure what I should do. Is there a better way to check if the username exists?