Reputation: 29
I got two tables in database called user user table and 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 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.
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.
Upvotes: 0
Views: 245
Reputation: 1002
You can Use
$this->db->last_query();
in simpan_upload()
before return.
it's show you insert query and you can correct it.
It will be determined that the ID_USER
has been sent.
Upvotes: 0