Unexpected result in database query

Asked

Viewed 34 times

0

<?php
class Login{
    public function logar($email,$senha){
        $connect=new DB;
        $connect=$connect->conectar();

        $sql="select * from usuarios where email='$email' and senha='$senha' and status='1' limit 1;";
        $buscar=mysqli_query($connect,$sql);
        $result=mysqli_num_rows($buscar);
        if ($result==1) {
            $log=1;
            $dados=mysqli_fetch_array($buscar);
            $_SESSION["email"]=$dados["email"];
            $_SESSION["senha"]=$dados["senha"];
            $_SESSION["nivel"]=$dados["nivel"];
            setcookie("logado",1);

        }
        if (isset($log)) {
            $flash="Logado com sucesso!";
        }else{
            $flash="Verifique se as informações inseridas estão corretas!";
        }
        echo $flash;
    }
}
?>

Is there something above that makes it impossible for the query to be other than '1'? We assume the following situation: in my database there is an email record:'[email protected]' and password: 'admin' why when executing this code by entering the correct information the answer shown on the screen is "Check that the information entered is correct!"?

  • The status of that user is as 1?

  • is yes, that same SQL was run in PHP Myadmin

  • how are the connection data entered? I’ve circled here without class and without logging Function, inserting the connection directly and worked

  • Not because you’re with limit 1, then mysqli_num_rows will be 0 or 1 always

1 answer

0

Thanks to those who commented, but I managed to fix it. Who interests, the problem was in the database where all records were saved with the status 0, in the SQL command it gives a SELECT... WHERE status=1.

Browser other questions tagged

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