duanjiu2701 2016-04-13 10:36
浏览 44

使用codeigniter在db中插入多个复选框值

I'm working on web app using codeigniter framework and setting privileges for different type of users so I need to add approximately 35 rows in db for each user and each row have 6 checkbox values (0,1). I'm having difficulty while storing these values in array and sending to MODEL for insertion.

Here is Controller code:

public function set_priv(){

    $data = array(
        array(

            'type_id' => $this->input->post('priv_type_id'),
            'module_name' => 'Classes',
            'can_access' => $this->input->post('classes[0]'),
            'can_insert' => $this->input->post('classes[1]'),
            'can_delete' => $this->input->post('classes[2]'),
            'can_update' => $this->input->post('classes[3]'),
            'can_export' => $this->input->post('classes[4]'),
            'can_print' => $this->input->post('classes[5]'),

            ),
        //  ),
    );

}

HTML Form Code for understanding Each check box for access, insert, update and delete privilege etc.

<div class="col-md-1">
   <input type="checkbox" name="classes[]" />
</div>
<div class="col-md-1">
    <input type="checkbox" name="classes[]" />
</div>
<div class="col-md-1">
    <input type="checkbox" name="classes[]" />
</div>
<div class="col-md-1">
    <input type="checkbox" name="classes[]" />
</div>
<div class="col-md-1">
    <input type="checkbox" name="classes[]" />
</div>
<div class="col-md-1">
    <input type="checkbox" name="classes[]"/>
</div>
  • 写回答

3条回答 默认 最新

  • dousi4900 2016-04-13 10:43
    关注

    Why you are using multidimensional array to insert the data? if you are getting checkbox value in array finely. I think it should be like.

    $data = array(
            'type_id' => $this->input->post('priv_type_id'),
            'module_name' => 'Classes',
            'can_access' => $this->input->post('classes[0]'),
            'can_insert' => $this->input->post('classes[1]'),
            'can_delete' => $this->input->post('classes[2]'),
            'can_update' => $this->input->post('classes[3]'),
            'can_export' => $this->input->post('classes[4]'),
            'can_print' => $this->input->post('classes[5]'),
        );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型