1
I am trying to verify the existence of a user in the database when it performs the login. The user and password are already created in the database, but even then the check only enters the else
.
logging in.php
<?php
include_once("conexao.php");
session_start();
$usuario = $_POST['usuario'];
$senha = $_POST['senha'];
$result = mysqli_query("SELECT * FROM `usuarios` WHERE `usuario` = '$usuario' AND `senha`= '$senha'");
if(mysqli_num_rows($result) > 0 )
{
$_SESSION['usuario'] = $usuario;
$_SESSION['senha'] = $senha;
header('location:teste1.php');
}
else{
unset ($_SESSION['usuario']);
unset ($_SESSION['senha']);
header('location:teste2.php');
}
?>
login.php
<?php
include_once("conexao.php");
session_start();
?>
<form class="login-form" name="loginform" method="post" action="logando.php">
<input type="text" placeholder="Usuário" name="usuario" required=""/>
<input type="password" placeholder="Senha" name="senha" required=""/>
<button type="submit">ENTRAR</button>
<p class="message"> Desenvolvido por: Marcos A. Massini</p>
</form>
<p class="text-center text-danger">
<?php
if(isset($_SESSION['loginErro'])) {
echo $_SESSION['loginErro'];
unset($_SESSION['loginErro']);
}
?>
</p>
php connection.
<?php
$servidor = "localhost";
$usuario = "root";
$senha = "";
$dbname = "cadastro";
$conn = Mysqli_connect($servidor, $usuario, $senha, $dbname) or print (mysql_error());
if(!Mysqli_connect($servidor, $usuario, $senha)) {
echo "Error ao conectar";
}
?>
You are encrypting passwords when registering in the database ?
– NoobSaibot
No no, the password is normal, login: free password: free, nothing encrypted.
– Marcos A. Massini
Your database connection is working ?
– NoobSaibot
Yes, the registration is working normally with this connection.
– Marcos A. Massini
Before the condition
if .. else
makes aprint_r($result);
orvar_dump($result);
to know if something is returning.– NoobSaibot
Oops, I got it. I put it this way:
– Marcos A. Massini
$result = "SELECT * FROM
usersWHERE
user= '$usuario' AND
password= '$senha'";
$resultado = mysqli_query($conn, $result); Não sei como faz pra ficar em formato de codigo...
– Marcos A. Massini