Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
Ambil data dari database lalu menyimpan ke table lain
saya mengambil data dari table transaksi untuk nantinya disimpan ke tabel pengembalian saat mengeksekusi, data tidak tersimpan apa yang salah 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'] = "Tabel 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 selesai($id_transaksi,$id_buku){
$data['user'] = $this->db->get_where('user',['username'=>$this->session->userdata('username')])->row_array();
$data['judul'] = "Denda";
$data['transaksi'] = $this->Transaksi_models->getTransaksiById($id_transaksi);
$this->form_validation->set_rules('tgl_kembali','TanggalK','required');
$this->form_validation->set_rules('denda','Denda','required');
$this->form_validation->set_error_delimiters('<p class="text-danger">','</p>');
if ($this->form_validation->run()==FALSE) {
$this->load->view('templates/header',$data);
$this->load->view('templates/aside',$data);
$this->load->view('kembali/konfirmasi');
$this->load->view('templates/footer');
}else{
$this->Kembali_models->simpan();
$this->Kembali_models->bukukembali($id_transaksi,$id_buku);
redirect('kembali');
}
}
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 bukukembali($id_transaksi,$id_buku){
$this->db->query("UPDATE `tb_buku` SET `jumlah_buku`=(jumlah_buku+1) WHERE id = '$id_buku'");
$this->db->query("DELETE FROM tb_transaksi WHERE id_transaksi = '$id_transaksi'");
}
public function simpan(){
$data = [
"id_transaksi" => $this->input->post('id_transaksi'),
"id_buku" => $this->input->post('id_buku'),
"nis" => $this->input->post('nis'),
"nama" => $this->input->post('nama'),
"tgl_pinjam" => $this->input->post('tgl_pinjam'),
"tgl_kembali" => $this->input->post('tgl_kembali'),
"denda" => $this->input->post('denda')
];
$this->db->insert('tb_pengembalian',$data);
}
}
view saat form mau menyimpan
<div class="content-wrapper">
<div class="panel-body">
<form action="" method="POST">
<?php echo validation_errors(); ?>
<div class="form-group">
<label>ID Transaksi</label>
<input type="text" class="form-control" id="id_transaksi" name="id_transaksi" value="<?= $transaksi['id_transaksi']?>" disabled>
</div>
<div class="form-group">
<label>ID Buku</label>
<input type="text" class="form-control" id="id_buku" name="id_buku" value="<?= $transaksi['id_buku']?>" disabled>
</div>
<div class="form-group">
<label>NIS</label>
<input type="text" class="form-control" id="nis" name="nis" value="<?= $transaksi['nis']?>" disabled>
</div>
<div class="form-group">
<label>Nama</label>
<input type="text" class="form-control" id="nama" name="nama" value="<?= $transaksi['nama']?>" disabled>
</div>
<div class="form-group">
<label for="tanggal">Tanggal Pinjam</label>
<input type="date" class="form-control" id="tgl_pinjam" name="tgl_pinjam" value="<?= $transaksi['tgl_pinjam']?>" disabled>
</div>
<div class="form-group">
<label for="tanggal">Tanggal Kembali</label>
<input type="date" class="form-control" id="tgl_kembali" name="tgl_kembali">
</div>
<div class="form-group">
<label>Denda</label>
<select class="form-control select2" name="denda" id="denda">
<option value="Denda">Denda</option>
<option value="Bebas Denda">Bebas Denda</option>
</select>
<?= form_error('denda','<small class="text-danger">','</small>') ?>
</div>
<button type="submit" name="selesai" class="btn btn-primary">Simpan</button>
</form>
</div>
</div>
1 Jawaban:
di bagian view bagian disabled <pre> <input type="text" class="form-control" id="id_transaksi" name="id_transaksi" value="<?= $transaksi['id_transaksi']?>" disabled> </pre>
ganti jadi
<pre> <input type="text" class="form-control" id="id_transaksi" name="id_transaksi" value="<?= $transaksi['id_transaksi']?>" readonly="readonly"> </pre> disabled diganti jadi readonly="readonly" kenapa ? karena Elemen dengan Disabled atribut tidak dikirimkan
Tanggapan
makasih koreksinya tapi udah saya ubah tetap tidak tersimpan.
apakah semua disabled sudah diganti readonly?