Postingan lainnya
Edit/update data dan foto dengan codeigniter
Assalamualaikum, Selamat Siang,
Mau minta saran, saya sedang membuat form upload. Load tampilan lancar tidak ada error, proses upload juga lancar, proses hapus data juga sama lancar, tapi begitu saya coba edit nama dan fotonya itu Error
"A Database Error Occurred Error Number: 1146
Table 'db_btam.array' doesn't exist
UPDATE Array SET `nama_gambar` = 'coba edit', `gambar` = 'gambar1575863836.jpg' WHERE `galeri` IS NULL
Filename: C:/xampp/htdocs/administrator/system/database/DB_driver.php
Line Number: 691"
saya ga paham kalo Database Error gini tuh salahnya dimana, minta tolong di cek ya
Controller
function edit_foto($id_gambar){
$where = array('id_gambar' => $id_gambar);
$data['galeri'] = $this->db->query
("select * from galeri where id_gambar='$id_gambar'")->result();
$this->load->view('admin/header');
$this->load->view('admin/editfoto',$data);
$this->load->view('admin/footer');
}
function update_foto(){
$id_gambar = $this->input->post('id_gambar');
$nama_gambar = $this->input->post('nama_gambar');
$this->form_validation->set_rules('nama_gambar',
'nama_gambar', 'required|min_length[4]');
if($this->form_validation->run() != false){
$config['upload_path'] = './assets/upload/';
$config['allowed_types'] = 'jpg|png|jpeg';
$config['max_size'] = '2048';
$config['file_name'] = 'gambar'.time();
$this->load->library('upload', $config);
$where = array('id_gambar' => $id_gambar);
$data = array(
'nama_gambar' => $nama_gambar,
'gambar' => $image['file_name']
);
if($this->upload->do_upload('foto')){
$image = $this->upload->data();
unlink('assets/upload/'.$this->input->post('old_pict', TRUE));
$data['gambar'] = $image['file_name'];
$this->m_balai->update_data($where, $data,'galeri');
}else {
$this->m_balai->update_data($where, $data,'galeri');
}
$this->m_balai->update_data($where,$data,'galeri');
redirect(base_url().'admin/galeri');
}else{
$where = array('id_gambar' => $id_gambar);
$data['galeri'] = $this->db->query("select * from galeri where id_gambar='$id_gambar'")->
result();
//$data['galeri'] = $this->m_balai->edit_data($where,'galeri')->result();
$this->load->view('admin/header');
$this->load->view('admin/editfoto',$data);
$this->load->view('admin/footer');
}
print_r($this->upload->display_errors());
}
Model
<?php
defined('BASEPATH') or exit ('No Direct Script Access Allowed');
class M_balai extends CI_Model{
function edit_data($where,$table){
return $this->db->get_where($table,$where);
}
function get_data($table){
return $this->db->get($table);
}
function insert_data($data,$table){
$this->db->insert($table,$data);
}
function update_data($table,$data,$where){
$this->db->update($table,$data,$where);
}
function delete_data($where,$table){
$this->db->where($where);
$this->db->delete($table);
}
public function find($where, $table){
$hasil = $this->db->where('id_berita', $where)
->limit(1)
->get($table);
if($hasil->num_rows() > 0){
return $hasil->row();
} else {
return array();
}
}
public function kosongkan_data($table){
return $this->db->truncate($table);
}
}
view editfoto
<div class="page-header">
<h3>Edit Foto</h3>
</div>
<?php foreach($galeri as $g){ ?>
<form action="<?php echo base_url().'admin/update_foto' ?>" method="post" enctype="multipart/form-data">
<div class="form-group">
<label>Nama Foto</label>
<input type="hidden" name="id" value="<?php echo $g->id_gambar; ?>">
<input class="form-control" type="text" name="nama_gambar" value="<?php echo $g->nama_gambar; ?>">
<?php echo form_error('nama_gambar'); ?>
</div>
<dir class="form-group">
<label>Gambar</label>
<?php
if(isset($g->gambar)){
echo '<input type="hidden" name="old_pict" value="'.$g->gambar.'">';
echo '<img src="'.base_url().'assets/upload/'.$g->gambar.'" width="30%">';
}
?>
<input name="foto" type="file" class="form-control">
</dir>
<div class="form-group">
<input type="submit" value="Update" class="btn btnprimary">
</div>
</form>
<?php } ?>
Mohon bantuannya, terima kasih
Tanggapan
emang ada nama table ini didalam code ? db_btam.array
coba di confignya itu error karena table db_btam.array itu tidak terdeteksi
bukannya kalau salah nulis db di config harusnya dari pas pertama upload udah salah? ini cuma pas mau ngedit data yg udah di upload baru muncul kaya bgtu
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban