dongyao2022 2016-08-22 11:32
浏览 41
已采纳

无法使用codeigniter在数据库中保存复选框值

I have a list of emails with checkbox, that look like this

enter image description here

I want that user is able to select multiple values and then save it in database

View

<?php
    $reg_attributes = array('id'=>'form','class'=>'form-horizontal');
    echo form_open('admin/assignrec/'.$data->id, $reg_attributes); 
        foreach($client as $rec_id): ?>
            <tr>
                <td> <?php echo form_checkbox('recid[]', $rec_id->id); ?> </td>
                <td><?php echo $rec_id->email; ?></td>
            </tr> 
        <?php 
            endforeach; 
            echo form_close(); 
        ?>

Controller

public function assignrec($dataid)
    {
        $chk = $this->input->post('recid');
        $this->admin_model->assign_rec($quickdataid) ; 
    }

Model

public function assign_rec($dataid)
    {
        foreach ($chk as $chkid)
            {
                $data = array(
                'requestid' => $dataid,
                'recruiterid' => $this->input->post('chkid')                        
                 );
            }
        $insert_request = $this->db->insert('rec', $data);
        return $insert_data;

    }

However i am not able to save values in database, can anyone please help me

  • 写回答

1条回答 默认 最新

  • duan19805 2016-08-22 11:37
    关注

    Your controller should be like

    public function assignrec($dataid)
        {
            $quickdataid= $this->input->post('recid');
            $this->admin_model->assign_rec(dataid,$quickdataid) ; 
        }
    

    Your model should be like

    public function assign_rec($dataid,$chk)
        {
            foreach ($chk as $chkid)
                {
                    $data = array(
                    'requestid' => $dataid,
                    'recruiterid' => $this->input->post('chkid')                        
                     );
                }
            $insert_request = $this->db->insert('rec', $data);
            return $insert_data;
    
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何查看h3c 5130s-28f-si交换机配置 及更改网口
  • ¥15 HFSS仿真喇叭天线阵列方向图出现异常
  • ¥15 blender自发光强度
  • ¥15 FIR滤波器算法设计与实现(利用库函数firdec()
  • ¥15 利用单片机产生正弦信号,来测量差分放大电路放大倍数和共模放大倍数的思路和仿真
  • ¥60 关于mavlink的论文咨询
  • ¥66 定制开发肯德基自动化网站下单软件
  • ¥15 中科院研发的TextMind(文心)
  • ¥20 vscode虚拟环境依赖包未安装
  • ¥15 odoo17关于owl开发js代码问题