无法在db中插入数据

时间:2016-10-20 09:08:16

标签: php

我需要帮助我尝试了一切,但没有任何作品不知道问题是什么。我希望当我检查然后插入如果取消选中然后删除但我的代码没有插入

       if($this->input->post()){

$select_assigned_ids = $this->input->post('assigned_ids[]');
    if ($this->form_validation->run() == FALSE) {
        foreach($select_assigned_ids as $tlusers){
            $data = array(
                        'user_id' => $tlusers
                    );
            $test = $this->assign_permission_model->insert($data);


            } 

}
}else{
    //Checkbox is unchecked....
  $q = 'Delete from assign_permission ';
   $this->section_permission_model->qwr($q); 
}

它不会在db

中插入任何值

2 个答案:

答案 0 :(得分:1)

就像这段代码你的定义数组$ data remove(,)所以插入数据

    if($this->input->post()){
    $select_assigned_ids = $this->input->post('assigned_ids[]');
        if ($this->form_validation->run() == FALSE) {
            foreach($select_assigned_ids as $tlusers){
                $data = array(
                            'user_id' => $tlusers
                        );
                $test = $this->assign_permission_model->insert($data);

                } 

    }
    }else{
        //Checkbox is unchecked....
      $q = 'Delete from assign_permission ';
      $this->section_permission_model->qwr($q); 
    }

答案 1 :(得分:1)

插入一些行代码插入数据flash maessge

if($this->input->post()){
$select_assigned_ids = $this->input->post('assigned_ids[]');
    if ($this->form_validation->run() == FALSE) {
        foreach($select_assigned_ids as $tlusers){
            $data = array(
                        'user_id' => $tlusers
                    );
            $test = $this->assign_permission_model->insert($data);

            } 
         $this->session->set_flashdata('msg', '<div id="message"  class="alert alert-success"><a class="close" data-dismiss="alert" onclick="self.close()">x</a>Success Messages </div>');
                    redirect('redirect your page link'); 
}
}else{
    //Checkbox is unchecked....
  $q = 'Delete from assign_permission ';
  $this->section_permission_model->qwr($q); 
}