我有一个具有类似表单输入名称的表单,我想将其插入到数据库表的不同行中。但是当我提交表单时,不会插入具有类似表单输入名称的输入。
这是我的观点
<div class="row">
<div class="col-xs-12">
<div class="item-block">
<div class="item-form">
<button class="btn btn-danger btn-float btn-remove"><i class="ti-close"></i></button>
<div class="row">
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<input type="text" name="skills_name[]" class="form-control" placeholder="Skill name, e.g. HTML">
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<div class="input-group">
<input type="text" name="skills_proficiency[]" class="form-control" placeholder="Skill proficiency, e.g. 90">
<span class="input-group-addon">%</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-12 duplicateable-content">
<div class="item-block">
<div class="item-form">
<button class="btn btn-danger btn-float btn-remove"><i class="ti-close"></i></button>
<div class="row">
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<input type="text" name="skills_name[]" class="form-control" placeholder="Skill name, e.g. HTML">
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<div class="input-group">
<input type="text" name="skills_proficiency[]" class="form-control" placeholder="Skill proficiency, e.g. 90">
<span class="input-group-addon">%</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-xs-12 text-center">
<br>
<button class="btn btn-primary btn-duplicator">Add experience</button>
</div>
</div>
</div>
</section>
<!-- END Skills -->
控制器:
function _get_skills_data(){
$data4['skills_name'] = $this->input->post('skills_name', TRUE);
$data4['skills_proficiency'] = $this->input->post('skills_proficiency', TRUE);
$session_data = $this->session->userdata('logged_in');
$data4['user_id'] = $session_data['user_id'];
return $data4;
}
if ($this->form_validation->run($this) == FALSE)
{
$this->add_resume();
}
else
{
$data4 = $this->_get_skills_data();
$this->User_model->insert_resume('skills',$data4);
$this->session->set_flashdata('message', '<div class="alert alert-success">Resume Added</div>');
redirect('user/manage_resume', 'refresh');
}
模型:
function insert_resume($table, $data){
$query = $this->db->insert($table, $data);
return $this->db->insert_id();
}
请问我出错了什么,我已经阅读了一些对我不起作用的问题。谢谢!
答案 0 :(得分:2)
根据Blinkydamo的评论你需要循环你的帖子数据,因为你试图将这些作为一个数组插入
尝试这样的事情:
The worker process failed to pre-load .Net Runtime version No Managed Code.
和您的第二个控制器功能代码段
function _get_skills_data()
{
$arrData = array();
$arrPostSkillsName = $this->input->post('skills_name', TRUE);
$arrPostSkillsProficiency = $this->input->post('skills_proficiency', TRUE);
$session_data = $this->session->userdata('logged_in');
$count = count($arrPostSkillsName);
for($i=0;$i<$count;$i++)
{
$arrItemData = array();
$arrItemData['skills_name'] = $arrPostSkillsName[$i];
$arrItemData['skills_proficiency'] = $arrPostSkillsProficiency[$i];
$arrItemData['user_id'] = $session_data['user_id'];
$arrData[] = $arrItemData;
}
return $arrData;
}