I can not find the login error

0

I'm logging in, but even when I put the data of a registered user, invalid data appears.

login.php

<?php

session_start();

require_once "Classes/UsuariosDAO.php";
require_once "Classes/UsuariosVO.php";

$objUsuario= new UsuariosVO();
$objBDUsuario= new UsuariosDAO();

$email=$_POST['HTML_email_USUARIO'];
$senha= md5($_POST['HTML_senha_USUARIO']);


$tmpLogin=$objBDUsuario->loginUsuario($email, $senha);

if($tmpLogin==null){
//dados invalidos
echo 'Dados Inválidos';

 }else{
$objUsuario=$tmpLogin;

$_SESSION['email']=$objUsuario->getEmail();
$_SESSION['nome']=$objUsuario->getNome();
$_SESSION['status']= true;
$_SESSION['msg']= "Olá, ". $_SESSION['nome']."!"; 

$rsDados=$objBDUsuario->permissaoUsuario($permissao);
$tblDados= mysql_fetch_array($rsDados);

header("location:Home.php");
}

ADO Users

function loginUsuario($tmpEmail, $tmpSenha){

$objBDpi = new BancoDAO();
    $objBDpi->AbreConexao();


$sqlLogin="Select * from usuarios where ";
$sqlLogin.="email_USUARIO like '$tmpEmail' ";
$sqlLogin.=" and ";
$sqlLogin.="senha_USUARIO like '$tmpSenha'";

 $mysqli = new mysqli('localhost', 'root', '', 'bdpi');

$rsLogin= mysqli_query($mysqli,$sqlLogin) or die($mysqli_error($mysqli));

if(mysqli_num_rows($rsLogin)>0){ 

    $tblLogin= mysqli_fetch_array($rsLogin);

    $tmpUsuario=new UsuariosVO();

    $tmpUsuario->setEmail($tblLogin['email_USUARIO']);
    $tmpUsuario->setNome($tblLogin['nome_USUARIO']);

    return $tmpUsuario;


}else{
   return null;

}
}

UsuariosVO.php

<?php
class UsuariosVO{
public $nome, $senha, $email;

function _construct(){
    $this->setNome("");
    $this->setSenha("");
    $this->setEmail("");

}
public function getNome() {
    return $this->nome;
}

public function getSenha() {
    return $this->senha;
}

public function getEmail() {
    return $this->email;
}


public function setNome($tmpNome) {
    $this->nome = $tmpNome;
}

public function setSenha($tmpSenha) {
    $this->senha = $tmpSenha;
}

public function setEmail($tmpEmail) {
    $this->email = $tmpEmail;
}




}
?>

BancoDAO.php

<?php

 class BancoDAO {
     public $usuario="root", $senha="";
     public $servidor="localhost", $banco="bdpi";



     function AbreConexao(){
         $mysqli = new mysqli('localhost', 'root', '', 'bdpi');
         mysqli_set_charset($mysqli,'UTF-8');
        // Verifica se ocorreu algum erro
     if (mysqli_connect_errno()) {
       die('Não foi possível conectar-se ao banco de dados: ' .    mysqli_connect_error());
exit();
     }
     }

        function FechaConexao(){
          mysqli_close();
      }
  }

I discovered that the error is between these lines:

 $rsLogin= mysqli_query($mysqli,$sqlLogin) or die(mysqli_error($mysqli)); if(mysqli_num_rows($rsLogin)>0){ tenho certeza. 

Pq if I modify to (mysqli_num_rows ($ rsLogin) == 0 and put an echo "Gave bad" instead of:

        $objUsuario=$tmpLogin; $_SESSION['email']=$objUsuario->getEmail(); $_SESSION['nome']=$objUsuario->getNome(); $_SESSION['status']= true; $_SESSION['msg']= "Olá, ". $_SESSION['nome']."!"; header("location:Home.php"); 

echo "Gave bad"

    
asked by anonymous 29.11.2017 / 12:26

1 answer

0

In the command below you have to put a return in place of echo.

It looks like this:

if($rsLogin->num_rows > 0){ 

$tblLogin= mysqli_fetch_array($rsLogin);

$tmpUsuario=new UsuariosVO();

$tmpUsuario->setEmail($tblLogin['email_USUARIO']);
$tmpUsuario->setNome($tblLogin['nome_USUARIO']);

return $tmpUsuario;

}

Also replace your loginUsuario method with the below.

function loginUsuario($tmpEmail, $tmpSenha){

$objBDpi = new BancoDAO();
    $objBDpi->AbreConexao();


$sqlLogin="Select * from usuarios where ";
$sqlLogin.="email_USUARIO like '$tmpEmail' ";
$sqlLogin.=" and ";
$sqlLogin.="senha_USUARIO like '$tmpSenha'";

$mysqli = new mysqli('localhost', 'root', '', 'bdpi');

if(mysqli_connect_errno())
    die();

$rsLogin= $mysqli->query($sqlLogin);

if($rsLogin->num_rows > 0){ 

    $tblLogin= mysqli_fetch_array($rsLogin);

    $tmpUsuario=new UsuariosVO();

    $tmpUsuario->setEmail($tblLogin['email_USUARIO']);
    $tmpUsuario->setNome($tblLogin['nome_USUARIO']);

    return $tmpUsuario;


}else{
   return null;

}
}
    
29.11.2017 / 14:59