mardi 22 mars 2016

row() return null for specific field

Im trying to save specific field from a record into a session, for my user-role. The problem here is i cannot take any other field except nama.

controller/verify_login

public function index(){
    $this->load->model('verify_login_model');
    $username = $this->input->post('username');
    $password = $this->input->post('password');
    $result = $this->verify_login_model->verify($username, $password);
    if($result == $username) {



        $name = $this->verify_login_model->getinfo($username);
        $this->session->set_userdata('logged_in', TRUE);
        $this->session->set_userdata('username', $username);
        $this->session->set_userdata('name', $name);

        $this->load->view('home_view');






    } else {
        redirect('login');
    }

model/verify_login_model

function verify($username, $password){
    $this->db->select('username', 'password');
    $this->db->from('tb_user');
    $this->db->where('username', $username);
    $this->db->where('password', MD5($password));
    $this->db->limit(1);

    $query = $this->db->get();
    if($query->num_rows()==1) {
        return $username;
    } else {
        return false;
    }
}

function getinfo($username) {
    $this->db->select('nama', 'username');
    $this->db->from('tb_userInfo');
    $this->db->where('username', $username);
    $this->db->limit(1);

    $query = $this->db->get();
    if($query->num_rows()==1) {

        $result = $query->row();

        return $result->nama;



    } else {
        return false;
    }
}

view

<?php echo $this->session->userdata['name']?>

the var_dump($result) : object(stdClass)#22 (1) { ["nama"]=> string(4) "test" }

if i change the return $result->nama; to $result->username; i get error : Undefined property: stdClass::$username even tho im sure 200% there's username field in the table, and tried the query directly.



row() return null for specific field

Aucun commentaire:

Enregistrer un commentaire