[英]How to parsing active session id as foreign key in Codeigniter
I got two tables in database called user user table and fileupload fileupload table . 我在数据库中有两个表,分别称为user user table和fileupload fileupload table 。 I've managed to input data to user table with its auto increment primary key, and now I'm attempting to insert fileupload table with foreign key from user table.
我已经设法通过其自动增量主键向用户表中输入数据,现在我正尝试从用户表中插入带有外键的fileupload表。 fileupload is useful for saving data from uploaded file and it'll use
ID_USER
session from user table as a foreign key in fileupload table. fileupload对于从上传的文件中保存数据很有用,它将使用用户表中的
ID_USER
会话作为fileupload表中的外键。
Here's my controller: 这是我的控制器:
function do_upload() {
$config['upload_path'] = './file_upload/';
$config['allowed_types'] = 'xls|xlsx';
$this->load->library('upload', $config);
if($this->upload->do_upload("file")){
$data = array('upload_data' => $this->upload->data(),
'id_user' => $this->session->userdata('ID_USER'));
$title= $this->input->post('judul');
$filename= $data['upload_data']['file_name'];
$id_user = $data['id_user']['ID_USER'];
$result= $this->M_dbstatmanagement->simpan_upload($title, $filename, $id_user);
echo json_decode($result);
}
}
here's the model: 这是模型:
function simpan_upload($title, $filename, $id_user) {
$data = array(
'TITLE' => $title,
'NAMA_FILE' => $filename,
'ID_USER' => $id_user
);
return $this->db->insert('fileupload', $data);
}
and here's the upload form upload form 这是上传表单上传表单
When I click upload button in upload form, nothing happen. 当我单击上载表单中的上载按钮时,什么也没有发生。 And when I check the fileupload table, no data was inserted.
当我检查fileupload表时,没有插入任何数据。
You can Use $this->db->last_query();
您可以使用
$this->db->last_query();
in simpan_upload()
before return. 返回之前在
simpan_upload()
。 it's show you insert query and you can correct it. 它表明您插入查询并且可以更正它。
It will be determined that the ID_USER
has been sent. 将确定已发送
ID_USER
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.