2017-02-26 57 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