【发布时间】:2011-09-25 17:43:27
【问题描述】:
我想在数据库表的一行中插入,使用以下 php 代码(foreach)跟随值,但插入后出现以下错误,我该怎么办?
价值观:
<div class="column">
<input type="text" name="start_date[1][]" value="1111">
<input type="text" name="end_date[1][]" value="1111">
<input type="text" name="price_change[1][]" value="1111">
</div>
<div class="column">
<input type="text" name="start_date[2][]" value="2222">
<input type="text" name="end_date[2][]" value="2222">
<input type="text" name="price_change[2][]" value="2222">
</div>
<div class="column">
<input type="text" name="start_date[3][]" value="3333">
<input type="text" name="end_date[3][]" value="3333">
<input type="text" name="price_change[3][]" value="3333">
</div>
PHP代码:
$residence_ups_input = $this->input->post('start_date');
$residence_upe_input = $this->input->post('end_date');
$residence_upc_input = $this->input->post('price_change');
var_dump($residence_ups_input); // output this is: nobool(false)
$residence_p = array();
foreach ($residence_ups_input as $idx => $name) { //line 134
$residence_p[] = array(
'start_date' => $residence_ups_input[$idx],
'end_date' => $residence_upe_input[$idx],
'price_change' => $residence_upc_input[$idx]
);
}
;
$data = array(
//'name' => $this -> input -> post('name'),
'residence_p' => json_encode($residence_p)
);
$this->db->insert('tour_foreign', $data);
错误:
遇到 PHP 错误
严重性:警告
消息:无效 为 foreach()
提供的参数文件名:inser.php
行 数量:134
【问题讨论】:
-
请在上面的 cod 中查看我的 值,它们是数组。
标签: php arrays codeigniter json