CodeIgniter Forums

Full Version: cannot save data into database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Please anyone, check this code for me and tell me what is wrong with my code. I cannot save data into database with my current code(it did not show any error):


Index.php
PHP Code:
<script>
 
   $(function(){
 
       
        function loadData
(args) {
 
           //code
 
           $("#tampil").load("<?php echo site_url('peminjaman/tampil');?>");
 
       }
 
       loadData();
 
       
        function kosong
(args) {
 
           //code
 
           $("#kode").val('');
 
           $("#judul").val('');
 
           $("#pengarang").val('');
 
       }
 
       
        
$("#simpan").click(function(){
 
           var nomer=$("#no").val();
 
           var pinjam=$("#pinjam").val();
 
           var kembali=$("#kembali").val();
 
           var nis=$("#nis").val();
 
           var jumlah=parseInt($("#jumlahTmp").val(),10);
 
           
            if 
(nis=="") {
 
               alert("Pilih Nis Siswa");
 
               return false;
 
           }else if (jumlah==0) {
 
               alert("pilih buku yang akan dipinjam");
 
               return false;
 
           }else{
 
               $.ajax({
 
                   url:"<?php echo site_url('peminjaman/sukses');?>",
 
                   type:"POST",
 
                   data:"nomer="+nomer+"&pinjam="+pinjam+"&kembali="+kembali+"&nis="+nis+"&jumlah="+jumlah,
 
                   cache:false,
 
                   success:function(html){
 
                       alert("Transaksi Peminjaman berhasil");
 
                       location.reload();
 
                   }
 
               })
 
           }
 
           
        
}) 
</
script>

<
legend><?php echo $title;?></legend>
<div class="panel panel-default">
    <div class="panel-body">
        <form class="form-horizontal" action="" method="post">
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-lg-4 control-label">No. Transaksi</label>
                    <div class="col-lg-7">
                        <input type="text" id="no" name="no" class="form-control" value="<?php echo $noauto;?>" readonly="readonly">
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="col-lg-4 control-label">Tgl Pinjam</label>
                    <div class="col-lg-7">
                        <input type="text" id="pinjam" name="pinjam" class="form-control" value="<?php echo $tanggalpinjam;?>" readonly="readonly">
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="col-lg-4 control-label">Tgl Kembali</label>
                    <div class="col-lg-7">
                        <input type="text" id="kembali" name="kembali" class="form-control" value="<?php echo $tanggalkembali;?>" readonly="readonly">
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-lg-4 control-label">Nis</label>
                    <div class="col-lg-7">
                        <!-- <select name="nis" class="form-control" id="nis">
                            <option></option>
                            <?php foreach($anggota as $anggota):?>
                            <option value="<?php echo $anggota->nis;?>"><?php echo $anggota->nis;?></option>
                            <?php endforeach;?>
                        </select> -->
                        <input type="text" class="form-control" id="nis" name="nis">
                    </div>
                </div>
                
                <div class="form-group">
                    <label class="col-lg-4 control-label">Nama Siswa</label>
                    <div class="col-lg-7">
                        <input type="text" name="nama" id="nama" class="form-control">
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="panel panel-success">
    <div class="panel-heading">
        Data Buku
    </div>
    
    <div class="panel-body">
        <div class="form-inline">
            <div class="form-group">
                <label>Kode Buku</label>
                <input type="text" class="form-control" placeholder="Kode Buku" id="kode">
            </div>
            <div class="form-group">
                <label class="sr-only">Judul Buku</label>
                <input type="text" class="form-control" placeholder="Judul Buku" id="judul" readonly="readonly">
            </div>
            <div class="form-group">
                <label class="sr-only">Pengarang</label>
                <input type="text" class="form-control" placeholder="Pengarang" id="pengarang" readonly="readonly">
            </div>
            <div class="form-group">
                <label class="sr-only">Pengarang</label>
                <button id="tambah" class="btn btn-primary"><i class="glyphicon glyphicon-plus"></i></button>
            </div>
            <div class="form-group">
                <label class="sr-only">Pengarang</label>
                <button id="cari" class="btn btn-default"><i class="glyphicon glyphicon-search"></i></button>
            </div>
        </div>
    </div>
    
    <div id="tampil"></div>
    
    <div class="panel-footer">
        <button id="simpan" class="btn btn-primary"><i class="glyphicon glyphicon-hdd"></i> Simpan</button>
    </div>
</div>




 <!-- Modal -->
            <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
              <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">Cari Buku</h4>
                  </div>
                  <div class="modal-body">
                        <div class="form-horizontal">
                            <label class="col-lg-3 control-label">Cari Nama Buku</label>
                            <div class="col-lg-5">
                                <input type="text" name="caribuku" id="caribuku" class="form-control">
                            </div>
                        </div>
                        
                        <div id="tampilbuku"></div>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary" id="konfirmasi">Hapus</button>
                  </div>
                </div><!-- /.modal-content -->
              </div><!-- /.modal-dialog -->
            </div><!-- /.modal --> 
related controller:
PHP Code:
 function index(){

        $data['title']="Transaksi Peminjaman";
        $data['tanggalpinjam']=date('Y-m-d');
        $data['tanggalkembali'] = strtotime('+7 day',strtotime($data['tanggalpinjam']));
        $data['noauto']=$this->m_peminjaman->nootomatis();
        $data['anggota']=$this->m_peminjaman->getAnggota()->result();
        $data['tanggalkembali'] = date('Y-m-d'$data['tanggalkembali']);
        $this->template->display('peminjaman/index',$data);
    }
    
    
function tampil(){
        $sess=$this->session->userdata('nis');
        $data['tmp']=$this->m_peminjaman->tampilTmp($sess)->result();
        $data['jumlahTmp']=$this->m_peminjaman->jumlahTmp();
        $this->load->view('peminjaman/tampil',$data);
    }
    
    
function sukses(){
        
        $tmp
=$this->m_peminjaman->tampilTmp()->result();
        foreach($tmp as $row){
            $info=array(
                'id_transaksi'=>$this->input->post('nomer'),
                'id_perpustakaan'=>$this->input->post('id_perpustakaan'),
                'nis'=>$this->input->post('nis'),
                'kode_buku'=>$row->kode_buku,
                'tanggal_pinjam'=>$this->input->post('pinjam'),
                'tanggal_kembali'=>$this->input->post('kembali'),
                'status'=>"N"
            );
            $this->m_peminjaman->simpan($info);
            
            
//hapus data di temp
            $this->m_peminjaman->hapusTmp($row->kode_buku);
        }
    
related model:
PHP Code:
private $table="transaksi";

function 
tampilTmp($sess){
 
       $this->db->where("id_keranjang",$sess);
 
       return $this->db->get("keranjang");
 
   }

function 
hapusTmp($kode){
 
       $this->db->where("kode_buku",$kode);
 
       $this->db->delete("keranjang");
 
   }

function 
simpan($info){
 
       $this->db->insert("transaksi",$info);