I do not receive SELECT FROM data

Asked

Viewed 52 times

0

I’m making 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 programming 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;

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

1 answer

0


It wouldn’t be because you’re not comparing the values sent with table columns, but with static strings 'email' and 'senha'? Try logging in exactly with these "email" and "password" credentials, to see what happens. And if necessary correct the query by deleting the quotes between the columns name:

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

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

Browser other questions tagged

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