Error in mysqli_query

Asked

Viewed 25 times

0

I’m creating a system of login and password only that is giving the problem and do not know how to solve if someone can give me the code already edited thank

<!DOCTYPE html>
<?php
    $conexao = mysqli_connect("localhost", "root", "");
    mysqli_select_db($conexao, "admin");
    session_start();
?>
<html lang="pt-br">
    <head>
        <meta charset="utf-8">
        <title>Login</title>
        <script language="javascript">
            function sucesso(){
                setTimeout("window.location='index.php'", 4000);
            }
            function failed(){
                setTimeout("window.location='login.html'", 4000);
            }
        </script>
    </head>
    <body>
        <?php
            $user = $_POST["user"];
            $pass = $_POST["pass"];

            $consulta = mysqli_query("SELECT * FROM usuarios WHERE usuario = '$user' AND senha = '$pass'") or die (mysqli_error($conexao));
            $linhas = mysqli_num_rows($consulta);

            if($linhas == 0){
                echo"O login falhou. Você será redirecionado para a página de login em 4 segundos.";
                echo"<script language='javascript'>failed()</script>";
            } else {
                $_SESSION["usuario"]=$_POST["user"];
                $_SESSION["senha"]=$_POST["pass"];
                echo"Você foi logado com sucesso. Redirecionando em 4 segundos.";
                echo"<script language='javascript'>sucesso()</script";
            }
        ?>
    </body>
</html>

Warning: mysqli_query() expects at least 2 Parameters, 1 Given in D: htdocs programs authenticate.php on line 25

  • 2

    "if someone can give me the already edited code" that’s not how Sopt works. Did you read the error message? It is very clear: it gives you the error line, the function where the error is and tells you what is wrong.

  • the problem is that I can not solve I’m beginner in php and I’m learning still if you can help me thank you

  • What you got from the error message?

  • I understood that "mysqli_query()" is waiting for at least 2 parameters but only 1, but I don’t know what is this parameter that it is asking @Andersoncarloswoss

  • 1

    And have you read the documentation of the function to find out what this parameter is?

  • 1

    I tried to read more not with you friend

  • 1

    You have the list of parameters there. There is not much difficulty. The first parameter that the function expects is $link, which is the return of mysqli_connect and the second is $query, referring to the SQL command. Make it a habit to read the documentation in your studies and especially learn how to use it. It has (practically) everything about the language.

  • if I were not to ask for more I could not give me a quick and definitive solution?

  • 1

    It is asking too much, yes. The solution is clear and fast. Just study a little the functions you are using. No use applying codes you don’t know what you do.

  • Alright Sorry for the inconvenience

Show 5 more comments
No answers

Browser other questions tagged

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