$usersearch
will contain a pointer to a query result set if the query is able to execute (regardless of whether there was a match), or if the query actually fails for some reason, it would hold a value of false
.
As such, you need to check against the result set to see if there are actually any records returned. Oftentimes this is simply done using mysql_num_rows()
. here is an example:
$usersearch=mysql_query("Select * FROM users WHERE username=$Searchboxinput");
if(false === $usersearch){
// there was a problem running the query
echo mysql_error();
} else if (mysql_num_rows($usersearch) === 0) {
// no results were found
} else {
// you have at least one record returned
}
I would also suggest you learn to use mysqli
or PDO
as the mysql_*
functions are deprecated.