-1
I am making an application and I have the following problem: I register a user, it shows in the database, when trying to login, even filling the fields correctly, the SESSION['em_white'] always returns in index.php and even more... the following errors appear:
Notice: Undefined index: usuario in C: wamp64 www app php login.php on line 4
Notice: Undefined index: password in C: wamp64 www app php login.php on line 5
LOGIN FILE.PHP
<?php
require '../config/conexao.php';
$usuario = $_POST['usuario'];
$senha = $_POST['senha'];
if (isset($usuario) && !empty($usuario) && isset($senha) && !empty($senha))
{
$sql = "SELECT * FROM users WHERE USUARIO = :usuario AND SENHA = :senha";
$query = $con->prepare($sql);
$query->bindValue(":usuario", $usuario);
$query->bindValue(":senha", md5($senha));
$query->execute();
if ($query->rowCount() == 1)
{
$user_logged = $query->fetchAll(PDO::FETCH_ASSOC);
print_r($user_logged);
$_SESSION["nome_usuario"] = $user_logged["USUARIO"];
$_SESSION["logado"] = true;
header('Location: ../pages/timeline.php');
exit();
}
else
{
$_SESSION['nao_autenticado'] = true;
header('Location: ../index.php');
exit();
}
}
else
{
$_SESSION['em_branco'] = true;
header('Location: ../index.php');
exit();
}
$con = null;
?>
INDEX.PHP file
<?php session_start(); ?>
<!DOCTYPE html>
<html lang="pt-br" dir="ltr">
<head>
<!-- JQUERY CDN -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js" charset="utf-8"></script>
<!-- SLICK CSS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js" charset="utf-8"></script>
<!-- FONTS AWESOME -->
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<!-- BOOTSTRAP CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<!-- ARQUIVO CSS -->
<link rel="stylesheet" href="css/master.css">
<meta charset="utf-8">
<title>EAC | LOGIN</title>
</head>
<body id="primaryBody">
<div class="container">
<div class="logMessages text-center">
<h1 class="logMessages_title mt-5 mb-4">WELCOME</h1>
<p class="logMessages_subtitle mb-5">HAVE FUN AS YOU NEVER HAVE FUN WHILE STUDYING</p>
</div>
<div class=" d-flex justify-content-center">
<div class="card shadow p-2" style="width: 20rem;">
<div class="card-body">
<div class="logForm">
<h3 class="mb-4">LOG IN</h3>
<!-- PHP CASO A AUTENTICAÇÃPO FALHE ELE IMPRIME NA TELA -->
<?php if(isset($_SESSION['nao_autenticado'])) { ?>
<!-- MENSAGEM DE ERRO -->
<div class="alert alert-danger">
<p>Usuário ou senha inválidos.</p>
</div>
<!-- FIM MENSAGEM DE ERRO -->
<?php } unset($_SESSION['nao_autenticado']); ?>
<!-- FIM DO PHP DE FALHA NA AUTENTICAÇÃO -->
<!-- PHP CASO A AUTENTICAÇÃPO FALHE ELE IMPRIME NA TELA -->
<?php if(isset($_SESSION['em_branco'])) { ?>
<!-- MENSAGEM DE ERRO -->
<div class="alert alert-warning">
<p>Preencha todos os campos.</p>
</div>
<!-- FIM MENSAGEM DE ERRO -->
<?php } unset($_SESSION['em_branco']); ?>
<!-- FIM DO PHP DE FALHA NA AUTENTICAÇÃO -->
<form class="logForm_form" action="php/login.php" method="post">
<div class="logForm_form_column">
<input class="mb-4" type="text" placeholder="Usuario" name="usuario">
<input class="mb-4" type="password" placeholder="Senha" name="senha">
</div>
<div class="logForm_form_row justify-content-between mb-4">
<div class="logForm_form_row_texts">
<input type="checkbox" id="remember" name="scales">
<label for="remember">Remember me</label>
</div>
<a href="#">Forgot your password?</a>
</div>
<button class="btn btn-primary mb-2" id="btnLogin">LOGIN</button>
<a class="btn btn-success mb-2" id="btnLogin" href="pages/register.php">REGISTER</a>
<a class="btn btn-secondary" id="btnLogin" href="pages/timeline.php">CONVIDADO</a>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- ARQUIVO JS -->
<script src="js/app.js" charset="utf-8"></script>
<!-- BOOTSTRAP JS -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-KsvD1yqQ1/1+IA7gi3P0tyJcT3vR+NdBTt13hSJ2lnve8agRGXTTyNaBYmCR/Nwi" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-nsg8ua9HAw1y0W1btsyWgBklPnCUAFLuTMS2G72MMONqmOymq585AcH49TLBQObG" crossorigin="anonymous"></script>
</body>
</html>
I look forward to someone helping me, grateful at once.
You shouldn’t have
type=submit
in the boot LOGIN?– Bernardo Lopes
It is not necessary as it is the only button inside the form, so it is already a Ubmit, the others are just stylized links of buttons.
– Braz Brz