Uncaught Error: Call to Undefined Function mysql_query()

Asked

Viewed 1,755 times

0

I am doing my login system and is giving the following error when logging in:

Fatal error: Uncaught Error: Call to Undefined Function mysql_query() thrown in D: xampp htdocs login.php on line 41

if (isset($_POST['entrar']) && $_POST['entrar'] == "login")
    {
    $usuario = $_POST['email'];
    $senha = $_POST['senha'];
    if (empty($usuario) || empty($senha))
        {
        echo "Prencha TODOS os campos";
        }
      else
        {
        $query = "SELECT nome, email, senha FROM usuarios WHERE email = '$email' AND senha = '$senha'";
        $result = mysql_query($query);
        $busca = mysql_num_rows($result);
        $linha = mysql_fetch_assoc($result);
        if ($busca > 0)
            {
            $_SESSION['nome'] = $linha['nome'];
            $_SESSION['email'] = $linha['email'];
            header('Location: index.php');
            exit;
            }
          else
            {
            echo "Login ou senha ligado";
            }
        }
    }

1 answer

0


Do not use the function mysql, use the mysqli.

We should not use functions of the "mysql" extension because its development has been discontinued; the extension will is already obsolete, that is, code using these functions does not work.

For more details see: Why should we not use mysql type functions_*?

  • 2

    Moderator’s note: answer restored because it answers yes to the question. By error, AP is using a version of PHP that no longer has the functions mysql_*.

  • 1

    Thank you worked out here!

  • @Alan007br Glad you liked the answers! But the best way to thank those who helped you is to mark "accept" the best answer and vote for all who helped you. This way you make sure that whoever wrote the answer gets something in return, as well as making the site cleaner and more useful for everyone. Adding a new answer like this (which is not an answer to the question and should be removed) makes the site more confusing and can get in the way.

Browser other questions tagged

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