Error in PHP login, registration is working normal, only login does not connect according to entries in the database

Asked

Viewed 53 times

0

YOU ARE MAKING THAT MISTAKE WHEN YOU GO IN :

Warning: mysqli_query() expects at least 2 Parameters, 1 Given in C: xampp htdocs hosste Login_v1 userauthentication.php on line 28

Warning: mysqli_error() expects Exactly 1 Parameter, 0 Given in C: xampp htdocs hosste Login_v1 userauthentication.php on line 28

<?php

$host = "localhost";    
$user = "root";    
$pass = "";    
$db = "tomorrow";    
$conexao =mysqli_connect($host, $user, $pass) or die (mysql_error());    
mysqli_select_db($conexao, $db) or die(mysql_error());

?>
<html>    
<head>    
    <title>Autenticando usuário</title>    
    <script type="text/javascript">    
        function loginsuccessfully() {    
            setTimeout("window.location='painel.php'",  5000);    
        }
        function loginfailed(){    
            setTimeout("window.location='login.php'",  5000);    
        }    
    </script>    
</head>    
<body>
    
    <?php
    
    $email=$_POST['email'];
    $senha=$_POST['senha'];
    $sql = mysqli_query("SELECT * FROM usuarios WHERE email = '$email' and senha = '$senha'") or die(mysqli_error());
    $row = mysqli_num_rows($sql);
    if($row > 0){
        session_start();
        $_SESSION['email']=$_POST['email'];
        $_SESSION['senha']=$_POST['senha'];
        echo "<center>Você foi autenticado com sucesso!</center>";
        echo "<script>loginsuccessfully()</script";
    } else {
        echo "<center>Nome de usuario ou senha invalido!</center>";    
        echo "<script>loginfailed()</script>";
    }
    
    ?>    
</body>    
</html>

inserir a descrição da imagem aqui

  • What var_dump($_POST) prints, so you send the form?

  • men did not understand, I saw in a tutorial that there

1 answer

0

You need to pass the link resource returned by mysqli_connect(), in your case you need to pass the variable $conexao as a pro parameter mysqli_query(). The same resource should be passed to the mysqli_error()

Should stay like this:

$sql = mysqli_query($conexao, "SELECT * FROM usuarios WHERE email = '$email' and senha = '$senha'") or die(mysqli_error($conexao));

Documentation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.