我在数组fromat中发布动态创建输入字段的值
<form method='post' action='<?php echo site_url('a3_bus_system/output')?>'>
<div class="_25">
<strong>Route Name/Number</strong>
<br/>
<input type="text" name=""></input>
</div>
<p> <p> </p></p>
<p> <p> </p></p>
<div id="div">
</div>
<p> </p><div class="_25">
<p><input type="button" name="button" class="button red" id="button" value="Add" onclick="generateRow() "/></a></p>
</div>
<input type='button' value='Remove Button' id='removeButton'>
<p> </p><p> </p></div>
<input type="submit" class="button blue" id="button" value="Register" />
/form>
</div>
</div>
<div class="clear height-fix"></div>
</div></div> <!--! end of #main-content -->
</div> <!--! end of #main -->
<script>
var counter=1;
function generateRow() {
var count="<font color='red'>"+counter+"</font>";
var temp =" <p> <div class='_25'><input type='textbox' id='textbox' name='stop["+counter+"]' placeholder='Stop Name'></input></div> <div class='_25'><input type='textbox' id='textbox' name='timing["+counter+"]' placeholder='Timing'></input></div> <div class='_25'><select id='ampm' name='ampm["+counter+"]'><option>a.m</option><option>p.m</option></select> </div>";
var newdiv = document.createElement('div');
newdiv.innerHTML = temp + count;
var yourDiv = document.getElementById('div');
yourDiv.appendChild(newdiv);
counter++;
}
</script>
现在我正在使用此codeigniter脚本将其发布到数据库
// form 1st text box input
foreach ($_POST['stop'] as $stopIndex => $stopValue) {
$sql="INSERT INTO t_routes_list(stop_name) VALUES('".$this->db->escape_str($stopValue)."')";
$this->db->query($sql);
}
// form 2nd text box input
foreach ($_POST['timing'] as $timingIndex => $timingValue)
{
$sql="INSERT INTO t_routes_list(timing) VALUES('".$this->db->escape_str($timingValue)."')";
$this->db->query($sql);
}
// form 3rd select box input
foreach ($_POST['ampm'] as $ampmIndex => $ampmValue) {
$sql="INSERT INTO t_routes_list(am_pm) VALUES('".$this->db->escape_str($ampmValue)."')";
$this->db->query($sql);
}
现在1想要仅输入数据1 1,但是当我发布时,所有字段都以空值发布
如何同时发布所有数据?
编码员请求帮助我使用php脚本答案 0 :(得分:0)
mate,在Codeigniter中存在Active Records
创建一个models/model_insert.php
ad hoc并放入一个插入函数:
class Model_Insert extends CI_Model{
function insert($data){
$this->db->insert('mytable',$data);
}
}
现在您只需在控制器中执行此操作即可在“mytable”中插入一些数据:
$this->load->model('model_insert');
$data = array('id'=>$id,'email'=>$email);
$this->model_insert->insert($data);