0
am logging in, but even when I put the data of a registered user appears invalid data.
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");
}
User
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();
}
}
found 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 "went bad" in place of:
$objUsuario=$tmpLogin; $_SESSION['email']=$objUsuario->getEmail(); $_SESSION['nome']=$objUsuario->getNome(); $_SESSION['status']= true; $_SESSION['msg']= "Olá, ". $_SESSION['nome']."!"; header("location:Home.php");
echo appears "It went bad"
Have you tried using a Try catch to get the Exception of the possible problem?
– Theotonio
I didn’t try, how do I do it?
– user98493
These links can help: What Try/Catch Blocks are for and when they should be used? and What are Try/Catch blocks? with Try/Catch. Just one question, your password is registered in the bank with MD5 encryption?
– UzumakiArtanis
thanks, I’ll take a look. Yes the password is saved in the bank on MD5
– user98493
You wouldn’t have to Return inside the if instead of echo in Usergo? instead of echo $tmpUsuario; do Return $tmpUsuario; ?
– Anderson Henrique
even then it was not... And I cannot find the error. Even if the user is registered will still appear invalid data. What will be?
– user98493
Ask the question the code of
BancoDAO
– NoobSaibot
put the code
– user98493
Ever tried to give a
echo $tmpEmail.' - '.$tmpSenha;
to know if the values are being received ? Try changing$sqlLogin.="email_USUARIO like '$tmpEmail' ";
and$sqlLogin.="senha_USUARIO like '$tmpSenha'";
for$sqlLogin.="email_USUARIO = '$tmpEmail' ";
and$sqlLogin.="senha_USUARIO ='$tmpSenha'";
– NoobSaibot
I’ve tried, nothing’s changed
– user98493