Login with PDO does not check number of results of select

0

I'm starting a new system only that instead of procedural I'm using O.O. and PDO, I started to login, but even to select returning the value, PHP shows that user or password is wrong ...

Login method:

static function login($usuario, $senha) {
    try {

        $con = ConnectionFactory::getConnection();

        $con->beginTransaction();

        $senha = base64_encode($senha);

        $stmt = $con->prepare("select usuario from tbl_login where usuario = '?' and senha = '?'");

        $stmt->bindParam(1, $usuario);
        $stmt->bindParam(2, $senha);

        $stmt->execute();
        $users = $stmt->fetchAll(PDO::FETCH_ASSOC);
        // tentei colocar tmb $stmt->rowCount() == 1
        if(count($users) == 1){
            echo '<script> alert("Bem vindo ao sistema!");
                           window.location("menu.php"); </script>';
        } else {
            echo '<script> alert("Usuário ou senha incorretos!");
                           window.location("login.php"); </script>';
        }
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
}
    
asked by anonymous 05.07.2018 / 03:50

1 answer

0

Return check is required.

//Pode usar o var_dump ou print_r
var_dump($users)
print_r($users)

I recommend var_dump

    
05.07.2018 / 17:30