Javascript 动态输入值不';t使用codeigniter保存在数据库中
我想让用户添加动态输入并将这些值保存在数据库中。但是使用这段代码,只有一个值保存到数据库中。如何将所有值保存到用户输入的数据库中 这是我对添加动态输入的看法Javascript 动态输入值不';t使用codeigniter保存在数据库中,javascript,codeigniter,Javascript,Codeigniter,我想让用户添加动态输入并将这些值保存在数据库中。但是使用这段代码,只有一个值保存到数据库中。如何将所有值保存到用户输入的数据库中 这是我对添加动态输入的看法 <script type="text/javascript"> $(document).ready(function() { var max_fields = 10; //maximum input boxes allowed var wrapper =
<script type="text/javascript">
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('</br><div><input class="input form-control"" name="mytext[]"/><a href="#" class="remove_field">Remove</a></div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
</script>
<div class="input_fields_wrap">
<div class="form-group">
<button type="button" class="btn btn-success add_field_button">Add More Fields</button>
</div>
<div>
<input class="input form-control" name="mytext[]">
</div>
</div>
函数错误(){
如果($this->input->post('mytext')){
$ATTACH=$this->input->post('mytext',true);
$data2=array();//$a){//需要索引来匹配其他属性
//附加数组
$data2[]=数组(
“mytext”=>$a,
“项目名称”=>$this->input->post('projectname'),
);
//对于同一表中的多个条目
$this->db->insert_batch('projectem',$data2);
重定向(“选择ctrl2/MODALADEMPLOYEES项目”);
}
}
}
请评论重定向()
并告诉我显示了什么错误。如果上述解决方案不起作用,请检查您是否在POST中获得了值。Kundan先生,我添加了我的界面,删除时出现了数据库表redirect@Dushee您希望如何在数据库test project test=a、b、c或project test=a、project test=b中存储值,项目测试=c
function error(){
if ($this->input->post('mytext')) {
$attain = $this->input->post('mytext', true);
foreach ($attain as $i => $a) { // need index to match other properties
$data2 = array(
'mytext' => $a,
'projectname' => $this->input->post('projectname'),
);
$this->db->insert('projectem', $data2);
redirect('Select_ctrl2/ModalAddEmployeesProject');
}
}
}
function error(){
if ($this->input->post('mytext')) {
$attain = $this->input->post('mytext', true);
$data2=array(); //<-initialize
foreach ($attain as $i => $a) { // need index to match other properties
//append array
$data2[] = array(
'mytext' => $a,
'projectname'=> $this->input->post('projectname'),
);
//for multiple entry in same table
$this->db->insert_batch('projectem', $data2);
redirect('Select_ctrl2/ModalAddEmployeesProject');
}
}
}