【问题标题】:How to parsing active session id as foreign key in Codeigniter如何在 Codeigniter 中将活动会话 ID 解析为外键
【发布时间】:2019-01-26 04:17:37
【问题描述】:

我在数据库中有两个名为 user user tablefileupload fileupload table 的表。我已经设法使用其自动增量主键将数据输入到 user 表中,现在我正在尝试使用 userfileupload 表/strong> 表。 fileupload 对于保存上传文件中的数据很有用,它将使用 user 表中的ID_USER session 作为 fileupload 表中的外键。
这是我的控制器:

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

这是模型:

function simpan_upload($title, $filename, $id_user) {
    $data = array(
        'TITLE' => $title, 
        'NAMA_FILE' => $filename, 
        'ID_USER' => $id_user 
    );
    return $this->db->insert('fileupload', $data); 
}

这是上传表单upload form

当我点击上传表单中的上传按钮时,什么也没有发生。当我检查 fileupload 表时,没有插入任何数据。

【问题讨论】:

  • 请在simpan_upload()return 之前使用echo($this->db->last_query() );。它显示您插入查询。
  • 您可以将会话保存在数据库中的表中。以及与其他表的关系。
  • @hamedhossani 我需要删除$result吗?所以它会return直接到$this->db->insert('fileupload', $data);
  • @hamedhossani 嘿,它适用于$this->db->last_query();。非常感谢。

标签: php mysql codeigniter phpmyadmin


【解决方案1】:

你可以使用 $this->db->last_query();simpan_upload() 返回之前。 它显示您插入查询,您可以更正它。

将确定ID_USER已经发送。

【讨论】:

    猜你喜欢
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-06
    • 2020-09-01
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    相关资源
    最近更新 更多