2017-02-26 54 views
0

我控制器笨MySQL的:插入记录不相同的用户ID为

// This will save all the updated values from the user. 
$id = $this->input->post('id'); 
$data = array(
    'full_name' => $this->input->post('name'), 
    'email'  => $this->input->post('email'), 
    'address' => $this->input->post('address'), 
    'phone'  => $this->input->post('phone') 
);  

    // And store user imformation in database. 
$cust_id = $this->cart_model->update_customer($data, $id); 

$order = array(
    'orderDate'  => date('Y-m-d'), 
    'customerid' => $cust_id 
); 
    // And store user order information in database. 
$ord_id = $this->cart_model->insert_order($order); 

我的模型

function update_customer($data, $id) 
{ 
    $this->db->where('id', $id); 
    $this->db->update('user', $data); 
    $id = $this->db->insert_id(); 
    return (isset($id)) ? $id : FALSE; 
} 

    // Insert order date with customer id in "orders" table in database. 
public function insert_order($data) 
{ 
    $this->db->insert('order', $data); 
    $id = $this->db->insert_id(); 
    return (isset($id)) ? $id : FALSE; 
} 

表顺序:idorderDatecustomerid

表用户:idfull_nameaddressphone

表订单价值0不一样的用户表,哪里是我的错,请customerid corected 感谢

回答

2
function update_customer($data, $id) 
{ 
    $this->db->where('id', $id); 
    $this->db->update('user', $data); 
    $id = $this->db->insert_id(); 
    return (isset($id)) ? $id : FALSE; 
} 

更新记录时,所以你应该删除该行你不能使用$this->db->insert_id();。 你已经传递了id作为函数参数,所以你可以直接返回,

function update_customer($data, $id) 
{ 
    $this->db->where('id', $id); 
    $this->db->update('user', $data); 
    return (isset($id)) ? $id : FALSE; 
} 
+0

谢谢你运行是succesfull – Anonymous