Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, Boolean Given in

Asked

Viewed 7,718 times

2

    $sql = "SELECT `id`, `nome`, `nivel` FROM `usuarios` WHERE (`usuario` = '".$usuario ."') AND (`senha` = '". sha1($senha) ."') AND (`ativo` = 1) LIMIT 1";
    $result = mysqli_query($conn, $sql);

    if (mysqli_num_rows($result) != 1) {

        echo "Login inválido!"; exit;

    } else {
        //
    }

Error:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in

2 answers

3

The problem is that your query has some error, so mysqli_query returns false and passing on that value to mysqli_num_rows causes the error

Before the if prints on screen the command (echo $sql;) and try to run the same on phpMyAdmin, Mysql Workbench or something like that, these softwares will show more exactly where the error is

  • It appeared here bro: SELECT id, nome, nivel FROM usuarios WHERE (usuario = 'test') AND (senha = '40bd001563085fc35165329ea1ff5c5ecbdbbeef') AND (ativo = 1) LIMIT 1 Warning: mysqli_num_rows() expects Parameter 1 to be mysqli_result, Boolean Given in /Storage/ssd5/850/7211850/public_html/validation.php on line 30 Invalid login!

0

To know how many lines came, you can try to do just like this stretch:

$result = mysqli_query($conn, $sql);
$arrDados = mysqli_fetch_assoc($result);
$nLinhas = count($arrDados);

if ($nLinhas == 1) {
    echo "Login Ok!";
    // Continua sua programação.
} else {
    echo "Login inválido!"; exit;
}       
  • Gave this error now: Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, Boolean Given in /Storage/ssd5/850/7211850/public_html/validation.php on line 29

Browser other questions tagged

You are not signed in. Login or sign up in order to post.