0

I am receiving the following error:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean ... on line 42

I have tried to test my SQL query directly in phpmyadmin and no error occurs. I cannot see why this is happening, since the query seems valid.

The code is:

$link = mysqli_connect($sql_host, $sql_usr, $sql_passwd,$sql_db);

if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$query = "SELECT Approver_Id, Approver_Name, Approver_Email FROM Approver WHERE Approver_Name=".$username."";

$result = mysqli_query($link,$query);

if (mysqli_num_rows($result) > 0) // <--- Line 42
{
    // Something top secret happens here ;)
}
MikaelKP
  • 133
  • 2
  • 18
  • 1
    `$username` must be inside quotes. Better use bind and prepare statement!! – Saty Jun 30 '16 at 09:56
  • write as '".$username."' and then final double quote(") as i written here $query = "SELECT Approver_Id, Approver_Name, Approver_Email FROM Approver WHERE Approver_Name='".$username."' "; – Devsi Odedra Jun 30 '16 at 09:56
  • 1
    Learn about prepared statements – Jens Jun 30 '16 at 09:58

0 Answers0