变量在codeigniter中返回为undefined?

时间:2013-08-02 18:34:47

标签: php codeigniter session variables undefined

我收到每个变量的以下错误消息:

第59,60,61,62行

Message: Undefined index:

我无法理解为什么因为它肯定会获得会话数据以及数据库的设置,并且他们是符合该标准的用户。

jobs.php(应用功能):

public function apply(){

if($this->session->userdata('is_logged_in')){
        $this->load->view('header');
        $this->load->view('job');

        $id = $this->session->userdata('id');

        $query = $this->db->get_where('jobseeker_profiles', array('jobseeker_id' => $id));
        $user = $query->row_array();

        $points = $user['total_points_value'];
        $name = $user['name'];
        $email = $user['email'];
        $jobseeker_profile_id = $user['id'];
        $employer_profile_id = $this->input->post('employer_id');
        $job_id = $this->input->post('job_id');

        $this->db->set('jobseeker_profile_id', $jobseeker_profile_id);
        $this->db->set('employer_profile_id', $employer_profile_id);
        $this->db->set('job_id', $job_id);
        $this->db->set('name', $name);
        $this->db->set('email', $email);
        $this->db->set('points_value', $points);

        if($this->input->post('submit')){
            $this->db->insert('applications');
        }

        redirect('applied-for');

    }else{
        redirect('login');
    }
}
}

希望你能提供帮助,谢谢!

2 个答案:

答案 0 :(得分:0)

您是否检查过您在这些行中设置的4个数据库变量是否在表中正确声明了?他们必须匹配工作。

答案 1 :(得分:0)

直接从控制器或模型中进行快速错误检查,如

 // check if query did not come back
 if ( ! $query = $this->db->get_where('jobseeker_profiles',array('jobseeker_id' => $id)) ) 
{ echo 'OMFG WHERE IS MY QUERY ???' ; } 
else
{   $user = $query->row_array(); 

    echo 'QUERY WORKED, User Name is:' . $user['name'] ;
}  

如果这不起作用,请返回并确保您正在加载数据库,用户/密码是否正确等等