没有从codeigniter中的数据库中获取用户名和ID

时间:2014-11-04 12:35:56

标签: php mysql codeigniter session

我已经更改了我的代码而且我收到了用户的电子邮件和密码,但无法获取姓名和ID?是什么问题?加上我得到一个错误未定义的索引ID和名称?

public function login() {
    $users = array (

            'email' => $this->input->post ( 'email' ),
            'password' => $this->input->post ( 'password' ),

            TRUE
    );

    if (count ( $users )) {

        $my_data = array (

                'email' => $users['email'],
                'password' => $users['password'],
                'name' => $users['name'],
                'id' => $users['id'],
                'loggedin' => TRUE
        );

        $this->session->set_userdata ( $my_data );
        var_dump($my_data);
    }
}

这是我的var_dump

'session_id' => string 'fa71c96123ea05c8c10ec8c49d125f5c' (length=32)
'ip_address' => string '127.0.0.1' (length=9)
'user_agent' => string 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:33.0) Gecko/20100101    
'last_activity' => int 1415150854
'user_data' => string '' (length=0)
'email' => string 'safir.syed@hotmail.com' (length=22)
'password' => string 'Kingston12' (length=10)
'name' => null
'id' => null
'loggedin' => boolean true

1 个答案:

答案 0 :(得分:1)

检查您的代码:

        public function login() {
        $users = array (

                'email' => $this->input->post ( 'email' ),
                'password' => $this->input->post ( 'password' ),
                'id' => $this->input->post ( 'id' ),
                'name' => $this->input->post ( 'name' )
        );

        if (count ( $users )) {

            $my_data = array (

                    'email' => $users['email'],
                    'password' => $users['password'],
                    'name' => $users['name'],
                    'id' => $users['id'],
                    'loggedin' => TRUE
            );

            $this->session->set_userdata ( $my_data );
            var_dump($my_data);
        }
    }