Count issue

I have a script that constantly comes up with a ‘1’ regardless of the search I run. The reason I found out was that in PHP 5 they changed the count command to output a 1 when the count string is empty. I will resist the temptation to ask why that made sense to the programmers at this time and ask the following question.

How can I rewrite the code below so that the if statement will come up false when no matches are found in the database instead of ‘1’.



$sql="SELECT id FROM users WHERE username ='" . $username . "'and password = '" . $password . "';";
	$result = mysqli_query($link, $sql); //queries the database
	if (count($result) == 1)
		{
			include 'main.html.php';
		}
	else
		{
			echo htmlspecialchars('Username and Password combination not found');
		}

count() returns the number of elements in an array.

$result is not an array but a resource.

Use mysql_num_rows() to return the number of rows in $result.

Sorry for the post… used empty instead… I didn’t realize I posted this thread…