PHP error, "Call to Undefined Function"

Asked

Viewed 10,486 times

2

Hello, I’m new to PHP and am having the following error:

Call to Undefined Function Realizarlogin()

What can it be ?

Code to call the function:

if(isset($_POST["btn-logar"]))
{
   include_once('../Controller/Login/Logar.php');

   RealizarLogin();
}

Code of the Function:

class Logar{

    var $usuario;
    var $senha;

    function RealizarLogin($usuario, $senha)
    {
        $this->$usuario = $_POST['usuario'];
        $this->$senha = $_POST['senha'];

        $login = $conn->prepare('SELECT count(1) as qtd FROM login WHERE usuario=:usuario AND senha=:senha');
        $login->bindParam(':usuario',$usuario);
        $login->bindParam(':senha',$senha);
        $login->execute();
        $retorno = $login->fetchAll();


        if($retorno[0]['qtd'] > 0)
        {
            session_start();
            $_SESSION['usuario'] = $usuario;
            $_SESSION['senha'] = $senha;

            print "<meta HTTP-EQUIV='Refresh' CONTENT='0;URL=../View/System/Home.php'>";
        } else {

            print "<meta HTTP-EQUIV='Refresh' CONTENT='0;URL=../View/Error/Error1.php'>";
        }
    }
  • 1

    Function does not exist or name has been typed wrong.

  • The name is correct, but I think I’m wrong when calling the function.

  • add the code to the question otherwise it is impossible to answer

  • Puts the file the function is also, this using linux?

1 answer

7


A function is different from a method, it cannot be invoked without the reference(object/class), to solve this create the object first and then call the method.

Your main file should stay:

if(isset($_POST["btn-logar"]))
{
   include_once('../Controller/Login/Logar.php');
   $login = new Logar();
   $login->RealizarLogin();
}

The keyword var was used in php4(legacy) to define properties a class, from php5 forward use the access modifiers, public, protected and private.

  • Thank you very much! Solved my problem.

Browser other questions tagged

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