2013-12-03 2 views
0

В приведенном ниже кодеригритовом коде я разместил контроллер и модель. Моя цель - сохранить имя колледжа сеанса в db. Я попытался, но он не входит в имя колледжа сеанса в 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(); 
     }//end the function 

модель:

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

ответ

0

изменить это:

$ this-> db-> вставка ('exam_table', данные $, $ data1);

к этому:

$ this-> db-> вставка ('exam_table', $ данных);

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

+0

Я попытался это сделать. Вы должны использовать метод «set» для обновления записи. Undefined variable: data1 – user2991258

+0

Вы пытались напечатать, если данные $ data и $ data1 имеют выход в контроллере, прежде чем передавать его в модель? – vahnevileyes

Смежные вопросы