The record is not found in the database when the user logs in

1

I'm trying to verify the existence of a user in the database when it logs in. The user and password are already created in the database, but even then the scan only enters else .

logando.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>

connection.php

<?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";
  }
?>
    
asked by anonymous 27.09.2017 / 09:41

1 answer

1

I believe the problem is occurring because you are not passing the appropriate parameters.

According to documentation of php, mysqli_query() asks for 2 arguments:

  • mysqli link - The connection link.

  • string query - The query you want to run.

  • With this, try to execute your query passing also the link:

    mysqli_query($conn, "SELECT * FROM 'usuarios' WHERE 'usuario' = '$usuario' AND 'senha'= '$senha'");
    
        
    27.09.2017 / 11:20