CODEIGNITER如何在登录user_ID时将user_ID插入mySQL

问题描述 投票:0回答:1

这是错误页面

无法添加或更新子行:外键约束失败(latihan_ci.adventure,CONSTRAINT adventure_ibfk_1 FOREIGN KEY(user_id)REFERENCES usersuser_id)ON UPDATE CASCADE)

INSERT INTO adventurenamecategoryplacestate)VALUES('semeru','gunung','asa','asd')

这是我的控制者

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

这是我的模特

public function getUserId()
    {
        return $this->db->get('users',['user_id']);
    }

所以当值为user_ID已经登录时,如何将user_ID添加到mySQL。谢谢很多

php mysql database codeigniter
1个回答
1
投票

当你登录时user_id商店在使用后的会话中

调节器

$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'),
];
© www.soinside.com 2019 - 2024. All rights reserved.