Fatal error: Call to a Member Function exec() on a non-object in

Asked

Viewed 517 times

0

I wonder where I’m going wrong?

 public function validar() {

    $dados = Connection::select("SELECT id_usuario,login_usuario,senha_usuario,nome_usuario,sobrenome_usuario,departamento_id FROM usuario WHERE login_usuario='" . $_POST['usuario_usuario'] . "'");
    Connection::close();

    foreach ($dados as $reg):
        if ($_POST['senha_usuario'] == $reg['senha_usuario']):
            Session::setValue('logado', true);
            Session::setValue('departamento', $reg['departamento_id']);
            Session::setValue('nome_usuario', $reg['nome_usuario']);
            Session::setValue('sobrenome_usuario', $reg['sobrenome_usuario']);
            Session::setValue('id_usuario', $reg['id_usuario']);

        else:
            echo "<script>alert('Dados inválidos!'); location.href= 'index.php';</script>";
        endif;
    endforeach;

    $data = date("d-m-y");
    $hora = date("H:i:s");
    $ip = $_SERVER['REMOTE_ADDR'];
    $usuario = $_SESSION['id_usuario'];

    $sql = "insert into logs (mensagem_log,data_log,hora_log,ip_log,usuario_log) values ('$data','$hora','$ip','$usuario')";

    Connection::exec($sql);

    header('Location: ' . URL);
}
  • Connection::close(); -> Is that right? I mean, you really want to fechar a conexão? Note: I don’t know much about PHP.

  • That’s right buddy, close after Insert. Thank you.

1 answer

2


The way you’re wearing it Connection::exec($sql); it tries to execute a query on an object that does not exist, because you closed the connection up there, so you should only close the connection Connection::close(); after the Connection::exec($sql);.

  • 1

    Thank you. That’s right.

Browser other questions tagged

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