在数据库中存储会话

时间:2013-12-03 11:51:57

标签: php codeigniter

在下面的codeigniter代码中,我放置了控制器和模型。我的目标是将会话学院名称存储在数据库中。我试过但是没有进入会话学院名称db.college_name是空白的。

控制器

function create() {
    $j=1; 
    $createcustomer = $this->input->post('createcustomer');

    if( $this->input->post('createcustomer') != false ) {
        foreach($createcustomer as $row_id) {
            //this is validation command to update on the screen
            $this->form_validation->set_rules("exam_name_" . $row_id, "'Exam name'","required");
            $this->form_validation->set_rules("month_". $row_id,"`Month`","required");
            $this->form_validation->set_rules("year_". $row_id,"`Year`","required","required|");
        }               
    }

    if ($this->form_validation->run() == FALSE) {
        $data["message"]="";
        $this->load->view("exam_view",$data);
    } else {
        while($j<=$this->uri->segment(3)) {
            $data = array(
                'exam_name' => $this->input->post('exam_name_'.$j),
                'month' => $this->input->post('month_'.$j),
                'year' => $this->input->post('year_'.$j)
            );
            $exam_name=$this->input->post('exam_name_'.$j);
            $data1 = $this->session->userdata("college_name");
            if ($exam_name != "") {     
                $this->exam_model->add_record($data,$data1);
                //  $this->load->view("success_msg",$data); 
            }

            $j++;
        } //end of while condition
    } //end of if condition

    redirect('exam_site', 'refresh');       
    //$this->index();
}

型号:

function add_record($data,$data1) {
    $this->db->insert('exam_table', $data,$data1);
    //$this->db->insert('exam_table', $data1);

    if ($this->db->_error_number() == 1062) {
        $this->session->set_flashdata('duplicate', 'duplicate');
    }

    if ($this->db->_error_number() == "") {
        $this->session->set_flashdata('create', 'create');
    }

    return;
}

1 个答案:

答案 0 :(得分:0)

改变这个:

$ this-&gt; db-&gt; insert('exam_table',$ data,$ data1);

到此:

$ this-&gt; db-&gt; insert('exam_table',$ data);

$ this-&gt; db-&gt; insert('exam_table',$ data1);

相关问题