Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
Data gagal tersimpan (SOLVED)
saya ingin menyimpan data tapi error muncul alert "Data gagal di tambah" kesalahannya dimana ya
controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Kembali extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Kembali_models');
$this->load->model('Transaksi_models');
$this->load->library('form_validation');
is_loggedin();
}
public function index()
{
$data['user'] = $this->db->get_where('user',['username'=>$this->session->userdata('username')])->row_array();
$data['judul'] = "Data Peminjaman";
$data['transaksi'] = $this->Kembali_models->getAllTrans();
$this->load->view('templates/header',$data);
$this->load->view('templates/aside',$data);
$this->load->view('kembali/index',$data);
$this->load->view('templates/footer');
}
public function denda($id_transaksi){
$data['user'] = $this->db->get_where('user',['username'=>$this->session->userdata('username')])->row_array();
$data['transaksi'] = $this->Transaksi_models->getTransaksiById($id_transaksi);
$data['tanggal_kembali'] = date('Y-m-d');
$data['judul'] = 'Detail denda';
$this->load->view('templates/header',$data);
$this->load->view('templates/aside',$data);
$this->load->view('kembali/denda');
$this->load->view('templates/footer');
}
public function simpan(){
$data1 = [
"idtransaksi" => $this->input->post('id_transaksi'),
"idbuku" => $this->input->post('kode_buku'),
"nis" => $this->input->post('nis'),
"nama" => $this->input->post('nama'),
"tglkembali" => $this->input->post('tanggal_kembali'),
"status_denda" => $this->input->post('status_denda'),
"keterangan" => $this->input->post('keterangan')
];
$this->Kembali_models->simpan($data1);
$result = $this->db->affected_rows();
if($result > 0){
echo "<script>
alert('Data berhasil di tambah');
window.location.href='".base_url().'kembali'."';
</script>";
} else {
echo "<script>
alert('Data gagal di tambah');
window.location.href='".base_url().'kembali'."';
</script>";
}
}
}
model
<?php
class Kembali_models extends CI_model{
public $table = 'tb_transaksi';
public function getAllTrans(){
return $this->db->get('tb_transaksi')->result_array();
}
public function simpan($data1){
$this->db->insert('tb_pengembalian',$data1);
}
}
view
<div class="content-wrapper">
<div class="panel-body">
<!-- <form action="" method="POST"> -->
<?php echo validation_errors(); ?>
<?php echo form_open('Kembali/simpan'); ?>
<div class="form-horizontal">
<div class="box-body">
<div class="form-group">
<label class="col-sm-2 control-label">ID Transaksi</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="idtransaksi" name="idtransaksi" value="<?= $transaksi['id_transaksi'];?>"
readonly >
</div>
</div>
</div>
</div>
<div class="form-horizontal">
<div class="box-body">
<div class="form-group">
<label class="col-sm-2 control-label">ID Buku</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="idbuku" name="idbuku" value="<?= $transaksi['id_buku'];?>" readonly>
</div>
</div>
</div>
</div>
<div class="form-horizontal">
<div class="box-body">
<div class="form-group">
<label class="col-sm-2 control-label">Nama</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="nama" name="nama" value="<?= $transaksi['nama']?>" readonly>
</div>
</div>
</div>
</div>
<div class="form-horizontal">
<div class="box-body">
<div class="form-group">
<label class="col-sm-2 control-label">Tanggal Kembali</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="tglkembali" name="tglkembali" value="<?= $tanggal_kembali?>" readonly>
</div>
</div>
</div>
</div>
<div class="form-horizontal">
<div class="box-body">
<div class="form-group">
<label class="col-sm-2 control-label">Status Denda</label>
<div class="col-sm-10">
<select class="form-control select2" name="status_denda" id="status_denda">
<option value="nominal">Denda Nominal</option>
<option value="ganti">Ganti Buku</option>
</select>
</div>
</div>
</div>
</div>
<div class="form-horizontal">
<div class="box-body">
<div class="form-group">
<label class="col-sm-2 control-label">Keterangan</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="keterangan" name="keterangan">
</div>
</div>
</div>
</div>
<div class="col-sm-1">
<button type="submit" name="simpan" class="btn btn-primary">Simpan</button>
</div>
</form>
</div>
</div>
0
1 Jawaban:
Coba die dump dulu atau coba pake insert langsung aja terus die dump liat hasilnya ada atau tidak <pre> $this->db->insert('tb_pengembalian', $data); </pre>
0