0

my controller

    // 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);

my model

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;
}

Table order : id, orderDate, customerid

Table user : id, full_name, address, phone

customerid in table order value 0 not the same as the user table, where is my mistake please corected Thanks

1 Answer 1

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;
}

You cant use $this->db->insert_id(); when updating a record so you should remove that line. You are already passing the id as function parameter so you could return that directly with

function update_customer($data, $id)
{
    $this->db->where('id', $id);
    $this->db->update('user', $data);
    return (isset($id)) ? $id : FALSE;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.