我想在數據庫表的一行上插入下面的php代碼(foreach
),但插入後得到以下錯誤,我該怎麼辦?json_encode在數據庫中插入值的問題
值:
<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);
錯誤:
A PHP Error was encountered
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: inser.php
Line Number: 134
請參閱我的**值**在上面的鱈魚,他們是陣列。 –