I do not receive data from SELECT FROM

0

I'm doing a simple login system but I never get a real line where

$sql = "SELECT * FROM $this->table WHERE 'email' = :email AND 'senha' = :senha";

But the email and password are correct, PHP Function:

public function logarUsuario(){
    try{
        $sql = "SELECT * FROM $this->table WHERE 'email' = :email AND 'senha' = :senha";
        $stmt = DB::prepare($sql);
        $stmt -> bindParam(":email", $this->email, PDO::PARAM_STR);
        $stmt -> bindParam(":senha", $this->senha, PDO::PARAM_STR);
        $stmt ->execute();
        return $stmt->fetch();
        echo $stmt->fetch();
    }catch (PDOException $e){
        echo "Error".$e->getMessage();
    }
}

Here is the schedule sending the data to the user class:

if (isset($_POST['logar'])):
    //Recebe os dados
    $email = $_POST['email'];
    $senha = md5($_POST['senha']);

    //Salva os dados na classe usuario
    $user->setEmail($email);
    $user->setSenha($senha);
    //Tenta logar
    if($user->logarUsuario()){
        echo"Logado com sucesso";
    }else{
        echo"Não foi possivel logar";
    }
endif;

In short: The data is registered, but it does not return the true search even with the right data.

    
asked by anonymous 19.08.2017 / 20:29

1 answer

0

Would not it be because you are not comparing values sent with table columns, but with static strings 'email' and 'senha' ? Try to log in exactly with these "email" and "password" credentials to see what happens. And if necessary correct the query, eliminating the quotation marks between the column names:

$sql = "SELECT * FROM $this->table WHERE email = :email AND senha = :senha";

There is still one more possible obstacle when the password column is written with a hash in the table. In this case the password will have to pass through the same hash before the comparison.

    
20.08.2017 / 18:44