当我在db中插入一个数组时,我在某些变量中得到错误“unidentified index”,即使它们都有相应的值。尝试使用print_r,它返回一个带有值的数组,但是当我尝试插入数组时,值变为null。我不明白为什么,我在代码中看不到错误。
这是我的控制器
public function test()
{
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$user_id = $session_data['user_id'];
$table_id = $this->input->post('table');
$start = $this->input->post('start');
$end = $this->input->post('end');
$query = $this->process_resto_list->test($table_id);
if ($query->num_rows() > 0)
{
$row = $query->row();
$resto_id = $row->resto_id;
$table_number= $row->table_number;
$table_size = $row->table_size;
}
//$resto_id = $session_data['user_id'];
$values = array(
'resto_id' => $resto_id,
'diner_id' => $user_id,
'date' => $this->input->post('date'),
'start_time' => $start,
'end_time' => $end,
'table_number' => $table_number,
'number_of_people' => $table_size,
);
if($this->process_resto_list->insert_reservation($values))
redirect('reservation_test/reservation', 'location');
//print_r($values);
}
这是我的模特
public function insert_reservation($values)
{
date_default_timezone_set("Asia/Manila");
$data = array(
'resto_id' => $values['resto_id'],
'diner_id' => $values['user_id'],
'date' => date('Y-m-d'),
'start_time' => $values['start'],
'end_time' => $values['end'],
'table_number' => $values['table_number'],
'number_of_people' => $values['table_size'],
);
return $this->db->insert('resto_reservations', $data);
}
使用print_r时,这是数组的结果
数组([resto_id] => 9 [diner_id] => 14 [日期] => [start_time] => 11:00 [end_time] => 13:00 [table_number] => 6 [number_of_people] => 4)
请帮我指出错误。谢谢
答案 0 :(得分:1)
在你的模特中。更改值如下
$data = array(
'resto_id' => $values['resto_id'],
'diner_id' => $values['diner_id'],
'date' => date('Y-m-d'),
'start_time' => $values['start_time'],
'end_time' => $values['end_time'],
'table_number' => $values['table_number'],
'number_of_people' => $values['number_of_people'],
);
答案 1 :(得分:0)
我刚刚用这个替换了我的模型。谢谢大家!
$data = array(
'resto_id' => $values['resto_id'],
'diner_id' => $values['diner_id'],
'date' => date('Y-m-d'),
'start_time' => $values['start_time'],
'end_time' => $values['end_time'],
'table_number' => $values['table_number'],
'number_of_people' => $values['number_of_people'],
);