Good evening!
I'm making a simple website, which displays a box with username and password that will be sent by form via the post method to the valida.php page . When comparing the user and password entered by the user, with the user and password predefined in an if / else, the page redirects to main.html, which is the correct one. However, when I change the code to get directly into the database, when the user enters the credentials and presses the button, it is sent to the same page .. I can not understand what is wrong ...
Follow the codes:
index.php
<form class="login100-form validate-form" method="POST" action="valida.php">
<div class="wrap-input100 validate-input">
<input class="input100" type="password" id="inputSenha" name="senha" placeholder="Digite a Senha" required>
<span class="focus-input100" data-placeholder=""></span>
</div>
<div id="botao">
<input type="submit" value="ENTRAR" name="botao" id="entrar" class="btn efeito efeito-1 botaoEnviar" style="color: black; font-weight: bold" autofocus>
</div>
valida.php
<?php
include_once("conexao.php");
if((isset($_POST['user'])) && isset($_POST['senha']))
{
$usuario = mysqli_real_escape_string($conn, $_POST['user']);
$senha = mysqli_real_escape_string($conn, $_POST['senha']);
$senha = md5($senha);
$sql = "SELECT * FROM tb_login WHERE user = '$usuario' && senha = '$senha' LIMIT 1";
$result = mysqli_query($conn, $sql);
$resultado = mysqli_fetch_assoc($result);
if(empty($resultado))
{
$_SESSION['loginErro'] = "Usuario ou senha incorretos.";
header("Location: index.php");
}
elseif(isset($resultado))
{
header("Location: main.html");
}
else
{
$_SESSION['loginErro'] = "Usuario ou senha incorretos.";
}
}
else
{
$_SESSION['loginErro'] = "Usuario ou senha incorretos.";
header("Location: index.php");
}
?>
connection.php
<?php
$servidor = "localhost";
$usuario = "root";
$senha = "";
$dbname = "bd_otica";
$conn = mysqli_connect($servidor, $usuario, $senha, $dbname);
if(!$conn)
{
die("Falha na conexão: " . mysqli_connect_error());
}else
{}
?>
Thanks for any help!