gpt4 book ai didi

mysql - Codeigniter MySQL : Insert record not be same with user id

转载 作者:行者123 更新时间:2023-11-29 07:03:51 25 4
gpt4 key购买 nike

我的 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);

我的模型

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_name地址电话

表订单值 0中的

customerid与用户表不一样,我的错误在哪里,请纠正谢谢

最佳答案

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 作为函数参数传递,因此您可以直接返回该 id

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

关于mysql - Codeigniter MySQL : Insert record not be same with user id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42470055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com