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 kali安装包如何解决,请给明确方案和步骤
  • ¥15 DEA软件进行企业创新效率的计算
  • ¥15 树莓派驱动42步进电机
  • ¥20 bevfusion mit可视化遇到的问题
  • ¥15 如何获得《人工智能工程技术人员》认证?
  • ¥100 悬赏破解EFS加密,速度
  • ¥30 用MATLAB画随t变化的函数图像,式中包含了累加求和,出现报错,不知道怎么办了,请解释一下
  • ¥200 求破解MFS加密,悬赏
  • ¥15 博弈论两人分100元问题
  • ¥20 求指导,stm32串口控制程序无法编译