0
My login validation is always returning the same value in my $Row variable.
Follows the code:
php connection.
<?php
define('HOST', '127.0.0.1');
define('USUARIO', 'root');
define('SENHA', '');
define('DB', 'login');
$conexao = mysqli_connect(HOST, USUARIO, SENHA, DB) or die('Não foi possível conectar');
login.php
<?php
session_start();
include('conexao.php');
if(empty($_POST['usuario']) || empty($_POST['senha'])) {
header('Location: index.html');
exit();
}
$usuario = mysqli_real_escape_string($conexao, $_POST['usuario']);
$senha = mysqli_real_escape_string($conexao, $_POST['senha']);
$query = $query = "select usuario_id, usuario from usuario where usuario = '$usuario' and senha = md5('$senha')";
$result = mysqli_query($conexao, $query);
$row = mysqli_num_rows($result);
if($row == 1) {
$_SESSION['usuario'] = $usuario;
header('Location: cadastro.html');
exit();
} else {
header('Location: index.html');
exit();
}
In my if($Row..) is always returned the Else, even with the user registered in the database, that is, independent of the user typed, wrong or not, the function redirects to index.html
Table structure
Note: The connection with the comic was successfully performed.
Hi friend, my form is as you wrote, and still with error.
– Gabriel Melo
You can post the contents of the index.html file?
– Vinicius.Silva
I discovered the error. When the field did the validation, it was searching for the password in the database user column. In my comic, I changed the name of the user and password columns, one by the other. Then it worked right.
– Gabriel Melo