简体   繁体   中英

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.

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

to this:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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