如何使用codeigniter将名称图像插入数据库

时间:2017-02-23 09:56:18

标签: php mysql codeigniter

插入带图像的数据

时出现此错误
  

遇到PHP错误   严重性:通知
  消息:未定义索引:gambar
  文件名:sec47logaccess / produk_adm.php

     
    

行号:81

  

查看

<div class="col-md-6 input group">
    <label>Stok :</label>
    <input type="number" name="stok" class="form-control" id="stok" value="1" required>
    <br>
</div>
<div class="col-md-6 input group">
    <label>Berat (KG) :</label>
    <input type="text" name="berat" class="form-control" id="berat" value="0.5" required>
    <br>
</div>
<div class="col-md-6 input group">
    <label>Gambar :</label>
    <input type="file" name="gambar" class="form-control" id="gambar" required>
    <br>
</div>
<div class="col-md-6 input group">
    <label>Point :</label>
    <input type="number" name="point" class="form-control" id="point" value="0" required>
    <br>
</div>

控制器

$config['upload_path']              = 'assets/img/produk';
    $config['allowed_types']        = 'gif|jpg|png|jpeg';
    $config['max_size']             = 1000;
    $config['overwrite']            = TRUE;
    //$config['max_width']          = 1024;
    //$config['max_height']         = 768;
    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload('gambar')) {

        $error = array('error' => $this->upload->display_errors());
        $this->load->view('user_log_as_admin/header');
        $this->load->view('user_log_as_admin/produk/add', $error);
        $this->load->view('user_log_as_admin/footer');
        log_helper("produk", "Gagal Menambah produk baru");

    } else {

        $target = $this->input->post('nama');
        $data = $this->upload->data();
        $data = $this->input->post();
        $data = $this->input->upload();
        $data['nama_depan'] = $this->data['nama_depan'];
        $this->produk_adm->add($data);
        log_helper("produk", "Menambah Produk ".$target."");
        redirect('trueaccon2194/produk');

    }

模型

function add($data){
    $data_produk = array(
        'nama_produk'   => $data['nama'],
        'slug'          => $data['slug'],
        'milik'         => $data['miliknya'],
        'jenis'         => $data['jenisnya'],
        'artikel'       => $data['artikel'],
        'merk'          => $data['merknya'],
        'keterangan'    => $data['editor1'],
        'tags'          => $data['tags'],
        'kategori'      => $data['kategori'],
        'parent'        => $data['parent'],
        'harga_retail'  => $data['retail'],
        'harga_odv'     => $data['odv'],
        'harga_net'     => $data['retail'],
        'diskon'        => $data['diskon'],
        'stok'          => $data['stok'],
        'berat'         => $data['berat'],
        'gambar'        => $data['gambar'],
        'point'         => $data['point'],
        'status'        => $data['aktif'],
        'dibuat'        => $data['nama_depan'],
        'tgl_dibuat'    => date('Y-m-d H:i:s'),
    );
    $this->db->insert('produk', $data_produk);
}

1 个答案:

答案 0 :(得分:-2)

尝试在'tgl_dibuat' => date('Y-m-d H:i:s')

之后删除“,”或逗号
function add($data){
$data_produk = array(
    'nama_produk'   => $data['nama'],
    'slug'          => $data['slug'],
    'milik'         => $data['miliknya'],
    'jenis'         => $data['jenisnya'],
    'artikel'       => $data['artikel'],
    'merk'          => $data['merknya'],
    'keterangan'    => $data['editor1'],
    'tags'          => $data['tags'],
    'kategori'      => $data['kategori'],
    'parent'        => $data['parent'],
    'harga_retail'  => $data['retail'],
    'harga_odv'     => $data['odv'],
    'harga_net'     => $data['retail'],
    'diskon'        => $data['diskon'],
    'stok'          => $data['stok'],
    'berat'         => $data['berat'],
    'gambar'        => $data['gambar'],
    'point'         => $data['point'],
    'status'        => $data['aktif'],
    'dibuat'        => $data['nama_depan'],
    'tgl_dibuat'    => date('Y-m-d H:i:s')
);
$this->db->insert('produk', $data_produk);

}

祝你好运:)