【发布时间】:2017-11-22 04:56:24
【问题描述】:
我是 Codeigniter 的新手,在将数组插入数据库时遇到了一些问题。不断弹出一个错误,我无法将数组插入到我的数据库中。
这是我的 HTML 表单:
<?= form_open('profile/profile_submit'); ?>
<table class="table table-hover table-striped table-responsive">
<thead>
<tr>
<th id="headCheckHide"></th>
<th><center>Name</center></th>
<th><center>Date of Birth</center></th>
<th><center>Occupation</center></th>
<th><center>Educ. attainment</center></th>
</tr>
</thead>
<tbody id="sibTable">
<tr class="product-item">
<td>
<input type="text" class="form-control form-input" name="siblingName[]">
</td>
<td>
<input type="text" class="form-control form-input" name="siblingBirthDate[]">
</td>
<td>
<input type="text" class="form-control form-input" name="siblingOccupation[]">
</td>
<td>
<select class="form-control form-input" name="siblingEducAttainment[]" >
<option value="" selected>-Please select-</option>
<option value="less than high school">less than high school</option>
<option value="Some college but no degree">Some college but no degree</option>
<option value="Associates Degree">Associates Degree</option>
<option value="Elementary Graduate">Elementary Graduate</option>
<option value="Secondary Graduate">Secondary Graduate</option>
<option value="College Graduate">College Graduate</option>
<option value="Master's Degree">Master's Degree</option>
<option value="Professional Degree">Professional Degree</option>
<option value="Doctorate Degree">Doctorate Degree</option>
</select>
</td>
</tr>
</tbody>
</table>
<?= form_submit('submit','Save', 'class="btn btn-outline-primary waves-effect"');?>
<?php echo form_close();?>
我的表单控制器
public function profile_submit(){
$siblings=array(
'name' => $this->input->post('siblingName'),
'birthDate' => $this->input->post('siblingBirthDate'),
'occupation' => $this->input->post('siblingOccupation'),
'educAttainment' => $this->input->post('siblingEducAttainment')
);
$this->profile_model->submit_profile($siblings);
redirect('profile','refresh'); //name of the html file
}
我的 (profile_model.php) 模型
function submit_profile($siblings){
$this->db->insert('tbl_st_profile_sibling',$siblings);
}
这是我的模型错误:无法将数组插入数据库。 有人可以帮忙吗?谢谢。
【问题讨论】:
-
如果你也给我们错误信息会更好。
标签: php mysql arrays codeigniter