GET method getting NULL

Asked

Viewed 54 times

0

GET METHOD GETTING NULL why?

Testing in the browser: [email protected]&senha=1241

Code:

session_start();
class Login
{
private $email;
private $senha;
private $db;

public function __construct(PDO $db){
    $this->db = $db;
}

public function autenticar($email, $senha){
    $query = "select * from clientes where email='$email' and senha=$senha";
    echo $query."<br>";
    $stmt = $this->db->prepare($query);
    $stmt->execute();

    if(($stmt->fetch())){
        $_SESSION['logado'] = true;
        return true;
    }
    else{
        $_SESSION['logado'] = false;
        return false;
    }
}
}
$email = htmlspecialchars($_GET['$email']);
$senha = htmlspecialchars($_GET['$senha']);
$db = new PDO("mysql:host=localhost;dbname=registroop","root","");
$login = new Login($db);
$resultado = $login->autenticar($email,$senha);




if($resultado)
echo "logado";
else
echo "não logado";

echo "<br>";
  • 2

    This question is only a misdigestion.

  • 2

    Exchange the $_GET['$email'] for $_GET['email'] and $_GET['$senha'] for $_GET['senha']. Removing the $.

  • I need to tell you never pass a password via GET?

1 answer

1


It was just your typo.

session_start();
    class Login
    {
    private $email;
    private $senha;
    private $db;

    public function __construct(PDO $db){
        $this->db = $db;
    }

    public function autenticar($email, $senha){
        $query = "select * from clientes where email='$email' and senha=$senha";
        echo $query."<br>";
        $stmt = $this->db->prepare($query);
        $stmt->execute();

        if(($stmt->fetch())){
            $_SESSION['logado'] = true;
            return true;
        }
        else{
            $_SESSION['logado'] = false;
            return false;
        }
    }
    }
    $email = htmlspecialchars($_GET['email']);
    $senha = htmlspecialchars($_GET['senha']);
    $db = new PDO("mysql:host=localhost;dbname=registroop","root","");
    $login = new Login($db);
    $resultado = $login->autenticar($email,$senha);




    if($resultado)
    echo "logado";
    else
    echo "não logado";

    echo "<br>";

Browser other questions tagged

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