1

I have a difficulty on my program. The error say :

A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_DB_mysqli_result::$level

Filename: controllers/Auth.php

Line Number: 30

Backtrace:

File: C:\xampp\htdocs\PKLTelkom\Telkom2\application\controllers\Auth.php Line: 30 Function: _error_handler

File: C:\xampp\htdocs\PKLTelkom\Telkom2\index.php Line: 315 Function: require_once

Here's my controller named "Auth" :

<?php
/**
* 
*/
class Auth extends CI_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->model('m_login');

    }

    public function index()
    {
        $this->load->view("login");
    }

    public function AksiLogin()
    {
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $passwordx = md5($password);
        $login = $this->m_login->data_login($username, $passwordx);
        $tes = count($login);
        if ($tes > 0) {
            //ambil detail data
            $row = $this->m_login->data_login($username, $passwordx);
            $level = $row->level;
            //daftarkan session
            $data_session = array('level' => $level);
            $this->session->set_userdata($data_session);
            //direct page
            if ($level == 'superadmin') {
                redirect('superadmin');
            }
            else if ($level == 'admin') {
                redirect('admin');
            }

        }
        else {
            $this->index();
        }
    }

    public function logout()
    {
        $this->session->unset_userdata("login");
        $this->session->unset_userdata("username");
        redirect ('index.php/auth');
    }
    }
?>

Here's my models named "M_Login" :

<?php
class M_login extends CI_Model
{

function data_login($username, $password)
{
 $this->db->where('username', $username);
 $this->db->where('password', $password);
 return $this->db->get('akun');
}
}
?>
2
  • Line 30 $level = $row->level;. You're not returning level in your query. Commented Dec 8, 2017 at 12:53
  • @ourmandave where should I return the level? Commented Dec 8, 2017 at 13:00

1 Answer 1

1

Looks like your return $this->db->get('akun'); on "M_login" model doesn't return object with the name level.

Try changing this line on "M_Login" model :

<?php
class M_login extends CI_Model
{

function data_login($username, $password)
{
$this->db->where('username', $username);
$this->db->where('password', $password);
return $this->db->get('akun')->row(); // change this line
}
}
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.