-3
I created a login system with php and mysql but I can’t log in even though I’m sure the data has been registered successfully. I don’t know what I did wrong. Look at the code:
<?php
$login2 = $_POST['loginlogar'];
$senha2 = $_POST['senhalogar'];
$link = mysqli_connect("localhost", "root", "", "bancolanche")
or die("<h1>Não foi possível conectar!!</h1>".mysqli_error());
$banco = mysqli_select_db($link, "bancolanche")
or die("<h1>Não foi possível abrir banco de dados!!</h1>". mysqli_error());
$sql = "SELECT login, senha FROM users";
$resulta = mysqli_query($link, $sql);
while ($book = $resulta->fetch_object()) {
$logindb = $book->login;
$senhadb = $book->senha;
}
if($login2 == "" || $senha2 == ""){
$_SESSION['msg'] = "<h1 style='color:red'>Erro ao logar! Há campos de preenchimento obrigatório em branco.</h1>";
header("Location: logar.php");
} else {
if($logindb==$login2 && $senhadb==$senha2){
$_SESSION['msg'] = "<h1 style='color:green'>Logoff realizado com sucesso!</h1>";
header("Location: index.html");
} else {
$_SESSION['msg'] = "<h1 style='color:red'>Erro ao logar! Usuário inexistente ou senha incorreta.</h1>";
header("Location: logar.php");
}
}
mysqli_close($link);
?>
Hello! Your code has a closing key left ( } ) IF with two ELSE does not work unless a condition is passed for the first ex:
if ($x == $y) {} elseif($x == $z) {} else {}
– Jhonata De souza