[英]CODEIGNITER how to insert user_ID to mySQL when that user_ID is logged in
this is the error page 这是错误页面
Cannot add or update a child row: a foreign key constraint fails ( latihan_ci
. adventure
, CONSTRAINT adventure_ibfk_1
FOREIGN KEY ( user_id
) REFERENCES users
( user_id
) ON UPDATE CASCADE) 不能添加或更新子行,外键约束失败( latihan_ci
。 adventure
,约束adventure_ibfk_1
外键( user_id
)参考文献users
( user_id
)ON UPDATE CASCADE)
INSERT INTO adventure
( name
, category
, place
, state
) VALUES ('semeru', 'gunung', 'asa', 'asd') 插入adventure
( name
, category
, place
, state
)VALUES(“ semeru”,“ gunung”,“ asa”,“ asd”)
and this is my controller 这是我的控制器
public function addTrip(){
$this->load->model('userModel');
$newTrip = ['name' => $this->input->post('name'),
'category' => $this->input->post('category'),
'place' => $this->input->post('place'),
'state' => $this->input->post('state'),
];
$data['users'] = $this->userModel->getUserId()->result();
$this->db->insert('adventure',$newTrip);
$this->db->insert('adventure',$data);
redirect('userController/profile');
}
and this is my Model 这是我的模特
public function getUserId()
{
return $this->db->get('users',['user_id']);
}
so how to add the user_ID to the mySQL when the value is user_ID that is already login..Thanks alot 所以当值是已经登录的user_ID时,如何将user_ID添加到mySQL。
when you are login at that time user_id
store in session after use 当您当时登录时, user_id
在使用后存储在会话中
controller 调节器
$newTrip = ['name' => $this->input->post('name'),
'category' => $this->input->post('category'),
'place' => $this->input->post('place'),
'state' => $this->input->post('state'),
'user_id'=>$this->session->userdata('userdata'),
];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.