Postingan lainnya
Inputan form tidak masuk ke database
ijin bertanya agan agan kalau form yg kita isi tidak masuk ke tabel data_sepatu dan database apa penyebab nya ya ,apa salah coding padahal tidak ada error ataupun alert
<?php
class Data_sepatu extends CI_Controller{
public function index()
{
$data['sepatu'] = $this->model_sepatu->tampil_data()->result();
$this->load->view('templates_admin/header');
$this->load->view('templates_admin/sidebar');
$this->load->view('admin/data_sepatu', $data);
$this->load->view('templates_admin/footer');
}
public function tambah_aksi()
{
$nama_spt =$this->input->post('nama_spt');
$keterangan =$this->input->post('keterangan');
$kategori =$this->input->post('kategori');
$harga =$this->input->post('harga');
$gambar =$_FILES['gambar']['name'];
if ($gambar =''){}else{
$config ['upload_path'] ='./uploads';
$config ['allowed_types'] ='jpg|jpeg|png|gif';
$this->load->library('upload', $config);
if(!$this->upload->do_upload('gambar')){
echo "Gambar gagal diUpload!";
}else {
$gambar=$this->upload->data('file_name');
}
}
$data = array (
'nama_spt' => $nama_spt,
'keterangan' => $keterangan,
'kategori' => $kategori,
'harga' => $harga,
'gambar' => $gambar
);
$this->model_sepatu->tambah_sepatu($data, 'tb_sepatu');
redirect('admin/data_sepatu/index');
}
}
9 Jawaban:
Coba liat model_sepatu difungsi tambah_sepatu
<pre> <?php
class Model_sepatu extends CI_Model{ public function tampil_data(){ return $this->db->get('tb_sepatu'); }
public function tambah_sepatu($data,$table){
$this-&gt;db-&gt;insert($table,$data);
}
} </pre>
<pre> $data = array ( 'nama_spt' => $nama_spt, 'keterangan' => $keterangan, 'kategori' => $kategori 'harga' => $harga, 'gambar' => $gambar ); </pre> coba pastikan column dan data yg mau diinput ada
atau coba buat kaya gini untk liat erronya
Model <pre> public function tambah_sepatu($data,$table){ $this->db->insert($table,$data); return $this->db->affected_row() > 0; } </pre>
Controller <pre> ... if($this->model_sepatu->tambah_sepatu($data, 'tb_sepatu')){ redirect('admin/data_sepatu/index'); }else{ echo "Gagal Memasukan <br/> Deskripsi Error " . $this->db->_error_message(); } </pre>
screenshoot : <a href='https://ibb.co/gRnZJXX'>ss</a>
masih dak ade masuk war,
kalau aku paksa akses data_sepatu/tambah_aksi
A PHP Error was encountered
Severity: Notice
Message: Undefined index: gambar
Filename: admin/data_sepatu.php
Line Number: 19
Backtrace:
File: C:\xampp\htdocs\toko_online\application\controllers\admin\data_sepatu.php Line: 19 Function: _error_handler
File: C:\xampp\htdocs\toko_online\index.php Line: 315 Function: require_once
view/admin/data_sepatu
<pre> <div class="container-fluid"> <button class="btn btn-sm btn-primary mb-3" data-toggle="modal" data-target="#tambah_sepatu"><i class="fas fa-plus fa-sm"></i> Tambah Sepatu</button>
&lt;table class="table table-bordered"&gt;
&lt;tr&gt;
&lt;th&gt;NO&lt;/th&gt;
&lt;th&gt;NAMA SEPATU&lt;/th&gt;
&lt;th&gt;KETERANGAN&lt;/th&gt;
&lt;th&gt;KATEGORI&lt;/th&gt;
&lt;th&gt;HARGA&lt;/th&gt;
&lt;th colspan="3"&gt;AKSI&lt;/th&gt;
&lt;/tr&gt;
&lt;?php
$no=1;
foreach ($sepatu as $spt) : ?&gt;
&lt;tr&gt;
&lt;td&gt;&lt;?php echo $no++ ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $spt-&gt;nama_spt ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $spt-&gt;keterangan ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $spt-&gt;kategori ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;?php echo $spt-&gt;harga ?&gt;&lt;/td&gt;
&lt;td&gt;&lt;div class="btn btn-success btn-sm"&gt;&lt;i class="fas fa-search-plus"&gt;&lt;/i&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td&gt;&lt;div class="btn btn-primary btn-sm"&gt;&lt;i class="fa fa-edit"&gt;&lt;/i&gt;&lt;/div&gt;&lt;/td&gt;
&lt;td&gt;&lt;div class="btn btn-danger btn-sm"&gt;&lt;i class="fa fa-trash"&gt;&lt;/i&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?php endforeach; ?&gt;
&lt;/table&gt;
</div> <!-- Modal --> <div class="modal fade" id="tambah_sepatu" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">FORM INPUT PRODUK</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <form accept="<?php echo base_url(). 'admin/data_sepatu/tambah_aksi'; ?>" method="post" enctype="open_multipart/form-data">
&lt;div class="form-group"&gt;
&lt;label&gt;Nama Sepatu&lt;/label&gt;
&lt;input type="text" name="nama_spt" class="form-control"&gt;
&lt;/div&gt;
&lt;div class="form-group"&gt;
&lt;label&gt;Keterangan&lt;/label&gt;
&lt;input type="text" name="keterangan" class="form-control"&gt;
&lt;/div&gt;
&lt;div class="form-group"&gt;
&lt;label&gt;Kategori&lt;/label&gt;
&lt;input type="text" name="kategori" class="form-control"&gt;
&lt;/div&gt;
&lt;div class="form-group"&gt;
&lt;label&gt;Harga&lt;/label&gt;
&lt;input type="text" name="harga" class="form-control"&gt;
&lt;/div&gt;
&lt;div class="form-group"&gt;
&lt;label&gt;Foto Sepatu&lt;/label&gt;&lt;br&gt;
&lt;input type="file" name="foto" class="form-control"&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="modal-footer"&gt;
&lt;button type="button" class="btn btn-danger" data-dismiss="modal"&gt;Keluar&lt;/button&gt;
&lt;button type="submit" class="btn btn-primary"&gt;Simpan&lt;/button&gt;
&lt;/div&gt;
&lt;/form&gt;
s
&lt;/div&gt;
</div> </div> </pre>
cobe gini... <pre> ... if(!$this->upload->do_upload('gambar')){ echo "Gambar gagal diUpload!"; }else { $informasi_file = $this->upload->data(); $gambar=$informasi_file["file_name"]; } ... </pre>
kalo mash gagal, kubantu lewat teamviewer jak, kirim idnye di WA
Tanggapan
Bantu aku dong kak, punya aku juga ga bisa input data, data yg di input tidak tampil di database
coba sintaks if nya dicek, gunakan == bukan =
coba form accept nya ganti jadi form action sebelum
<pre> <form accept="<?php echo base_url(). 'admin/data_sepatu/tambah_aksi'; ?>" method="post" enctype="open_multipart/form-data"> </pre>
sesudah
<pre> <form action="<?php echo base_url(). 'admin/data_sepatu/tambah_aksi'; ?>" method="post" enctype="open_multipart/form-data"> </pre>
setau ane atribut accept itu buat nentuin jenis file yang diterima server, kalo sekarang attribut tersebut ga support html5