0
I am creating a login system and would like to know what is causing the errors
Notice: Undefined variable: e in C: xampp htdocs login CLASSES usuarios.php on line 14
Fatal error: Uncaught Error: Call to a Member Function getMessage() on null in C: xampp htdocs login CLASSES usuarios.php:14 Stack trace: #0 C: xampp htdocs login index_vacc.php(57): Usuario->connect('project_login', 'localhost', 'root') #1 {main} thrown in C: xampp htdocs login CLASSES usuarios.php on line 14
The index is:
<?php
require_once 'CLASSES/usuarios.php';
$u = new Usuario();
?>
<html lang="pt-br">
<body>
<div class="container">
<div class="content first-content">
<div class="first-column">
<h2 class="title title-grey">Olá, bem vindo(a) à plataforma</h2>
<h2 class="title title-grey">de prestação de contas.</h2>
</div>
<div class="second-column">
<h2 class="title title-white">Entrar</h2>
<p class="description">Faça o login para o acesso</p>
<form method="POST">
<label class="label-input" for="">
<i class="far fa-envelope icon-modify"></i>
<input type="email" name="email" placeholder=" E-mail">
</label>
<label class="label-input" for="">
<i class="fas fa-lock icon-modify"></i>
<input type="password" name="senha" placeholder=" Senha">
</label>
<button type ="submit" class="btn btn-grey">login</button>
</form>
</div>
</div>
</div>
<?php
if(isset($_POST['email']))
{
$email = addslashes($_POST['email']);
$senha = addslashes($_POST['senha']);
if(!empty($email) && !empty($senha))
{
$u->conectar("projeto_login", "localhost", "root", "");
if($u->msgErro == "")
{
if($u->logar($email,$senha))
{
header("location: AreaPrivada.php");
}
else
{
echo "Email e/ou senha estão incorretos!";
}
}
else
{
echo "Erro: ".$u->msgErro;
}
}
else
{
echo "Preencha todos os campos!";
}
}
?>
</body>
</html>
And the part of connection functions:
<?php
Class Usuario
{
private $pdo;
public $msgErro = "";
public function conectar($nome, $host, $usuario, $senha)
{
global $pdo;
global $msgErro;
try {
$pdo = new PDO("mysql:dbname=".$nome.";host=".$host, $usuario, $senha);
} catch (PDOException $e) {
$msgErro = $e->getMessage();
}
}
public function logar($email, $senha)
{
global $pdo;
$sql = $pdo->prepare("SELECT id_usuario FROM usuarios WHERE email = :e AND senha = :s");
$sql->bindValue(":e", $email);
$sql->bindValue(":s", md5($senha));
$sql->execute();
if ($sql->rowCount() > 0)
{
$dado = $sql->fetch();
session_start();
$_SESSION['id_usuario'] = $dado['id_usuario'];
return true;
}
else
{
return false;
}
}
}
?>
I’ve tried to declare a public $e but apparently it didn’t work.