将动态复选框值保存到数据库

时间:2019-01-22 20:09:30

标签: jquery codeigniter-3

我正在使用jquery和codeigniter将动态复选框值保存到数据库。单击保存按钮后,可以在jquery函数中正确显示复选框值。我的问题是无法将这些值插入数据库。请告诉我我的密码有何地方。

谢谢。

1-视图

<table>
<thead>
<tr>
<th>List</th><th >Check</th>
</tr>
</thead>
<tbody>
<?php
foreach($val1 as $row){
?>
<tr>
<td>
<?=$row->description;?>
</td>
<td>
<input type='checkbox'  name="cie10"  value="<?=$row->idd?>"  />
</td>

</tr>
<?php
}
?>
</tbody>
</table>

 <button id="save">save</button>

2- JQUERY

$('#save').on('click', function(event) {
var cie10 = [];
$.each($("input[name='cie10']:checked"), function(){            
cie10.push($(this).val());
;
});
alert(cie10);
var id_pat=100;
$.ajax({
type:'POST',
url:'<?=base_url('admin/savePatientCied')?>',
data: {cie10:cie10,id_pat:id_pat},
success:function(data) {

}});

})

3-控制器

public function savePatientCied()
{
$id_pat = $this->input->post('id_pat');
$cied10 = $this->input->post('cied10');

$id_con=1;

foreach ($cied10 as $key=>$id_ced) {
$save= array(
'diagno_def' => $id_ced,
'con_id_link' => $id_con,
'p_id' =>$id_pat
);
$this->model_admin->SaveConDef($save);
}
}

模型

public function SaveConDef($save) {
$this->db->insert('tablename', $save);
}

0 个答案:

没有答案
相关问题