Fatal error: Call to a member function exec () on a non-object in

0

Where am I 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);
}
    
asked by anonymous 26.02.2016 / 15:37

1 answer

2

As it is, using 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 Connection::exec($sql); .

    
26.02.2016 / 17:00