简体   繁体   English

将会话存储在数据库中

[英]To store session in database

In the below codeigniter code I have placed the controller and model. 在下面的代码点火器代码中,我放置了控制器和模型。 My aim is to store the session college name in the db. 我的目的是将会话大学名称存储在数据库中。 I tried but it is not entering the session college name into db.college_name is in blank. 我试过了,但是没有在db.college_name输入会话大学名称。

Controller 控制者

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();
}

Model: 模型:

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;
}

change this: 改变这个:

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

to this: 对此:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM