簡體   English   中英

將會話存儲在數據庫中

[英]To store session in database

在下面的代碼點火器代碼中,我放置了控制器和模型。 我的目的是將會話大學名稱存儲在數據庫中。 我試過了,但是沒有在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;
}

改變這個:

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

對此:

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM