Giamana cara simpan ini ketika menggunakan input type submit dua kayak gini

 <?php

include "inc/koneksi.php";
  $username  = $_SESSION['id_user'];

# HAPUS DAFTAR
if(isset($_GET['Aksi'])){
  if(trim($_GET['Aksi'])=="Hapus"){
    $id     = $_GET['id'];

    // Hapus Tmp jika datanya sudah dipindah
    $mySql = "DELETE FROM peminjaman_tmp WHERE id='$id' AND id_user='$username'";
    mysql_query($mySql);
  }
}
// =========================================================================

# TOMBOL TAMBAH DIKLIK
if(isset($_POST['btnTambah'])){
  // Baca Variabel
  $kd_karyawan   = $_POST['kd_karyawan'];
  $kd_brg    = $_POST['kd_brg'];

    # SIMPAN DATA BUKU KE TMP
    // Jika jumlah error pesanError tidak ada, skrip di bawah dijalankan
    $tmpSql   = "INSERT INTO peminjaman_tmp (kd_brg, id_user) VALUES ('$kd_brg','$username')";
    mysql_query($tmpSql);

}

# ========================================================================================================
# JIKA TOMBOL SIMPAN TRANSAKSI DIKLIK
if(isset($_POST['btnSimpan'])){
  // Baca variabel data form
  $tgl_pinjam   = $_POST['tgl_pinjam'];
  $kd_karyawan   = $_POST['kd_karyawan'];
  $lokasi  = $_POST['lokasi'];
  $ket    = $_POST['ket'];

  // Skrip Validasi form

    # SIMPAN KE DATABASE
    // Jika jumlah error pesanError tidak ada, maka proses Penyimpanan akan dikalkukan



    // Skrip menyimpan data ke tabel transaksi utama
    $mySql  = "INSERT INTO peminjaman(kd_peminjaman, kd_karyawan,tgl_pinjam, lokasi, ket,  status, id_user)
          VALUES ('$kd_peminjaman', '$kd_karyawan', '$tgl_pinjam', '$lokasi', '$ket', 'Pinjam', '$userLogin')";
    mysql_query($mySql);

    // Ambil semua data buku/buku yang dipilih (diambil dari TMP), berdasarkan user yg login
    $tmpSql ="SELECT * FROM peminjaman_tmp WHERE id_user='$username' ";
    $tmpQry = mysql_query($tmpSql, $koneksidb) or die ("Gagal Query baca Tmp".mysql_error());
    while ($tmpData = mysql_fetch_array($tmpQry)) {
      // Membaca data dari tabel TMP
      $kd_brg   = $tmpData['kd_brg'];


      // Masukkan semua buku/buku dari TMP ke tabel peminjaman detil
      $itemSql = "INSERT INTO peminjaman_detil(kd_peminjaman, kd_brg)
            VALUES ('$kd_peminjaman', '$kd_brg')";
      mysql_query($itemSql);
    }

    // Kosongkan Tmp jika datanya sudah dipindah
    $hapusSql = "DELETE FROM peminjaman_tmp WHERE id_user='$username' ";
    mysql_query($hapusSql);



}
# VARIABEL DATA DARI & UNTUK FORM
$kd_peminjaman   = isset($_POST['kd_peminjaman']) ? $_POST['kd_peminjaman'] : '';
$kd_karyawan   = isset($_POST['kd_karyawan']) ? $_POST['kd_karyawan'] : '';
$tgl_pinjam    = isset($_POST['tgl_pinjam']) ? $_POST['tgl_pinjam'] : '';
$lokasi   = isset($_POST['lokasi']) ? $_POST['lokasi'] : '';
$ket   = isset($_POST['ket']) ? $_POST['ket'] : '';
$dataKategori = isset($_POST['id_kategori']) ? $_POST['id_kategori'] : '';
date_default_timezone_set("Asia/Bangkok");

?>
<script language="JavaScript">
function submitform() {
  document.form2.submit();
}
</script>
<section id="header">
<h3><i class="fa fa-angle-right"></i> Input Data Peminjaman Barang</h3>
 <tr>
    <td colspan="2" align="right"><a href="index_admin.php?page=form-peminjaman-barang" ><img src="images/btn_add.png" height="30" border="0" /></a> <a href="index_admin.php?page=form-peminjaman-barang" ><img src="images/btn_view.png" height="30" border="0" /></a></td>
  </tr>
</section>
            <!-- BASIC FORM ELELEMNTS -->
<div class="row mt">
  <div class="col-lg-12">
    <div class="form-panel">
      <h4 class="mb"><i class="fa fa-angle-right"></i> Data Peminjaman Barang</h4>
      <form class="form-horizontal style-form" action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="form2" target="_self">
        <div class="form-group">
          <label class="col-sm-3 control-label">Kode Peminjaman</label>
          <div class="col-sm-7">
            <input type="text" class="form-control" name="kd_peminjaman" autocomplete="off" required value="<?php echo $kd_peminjaman; ?>">
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label" >Nama Karyawan</label>
          <div class="col-sm-7">
            <select type="text" name="kd_karyawan" class="form-control chosen-select" maxlength="64" required value="<?php echo $kd_karyawan; ?>" >
            <?php $sql = mysql_query("select kd_karyawan, nama_karyawan from karyawan ");
            while ($data = mysql_fetch_array($sql)){
            ?>
            <option value="<?php echo $data['kd_karyawan'];?>"><?php echo $data['kd_karyawan'] ?> -- <?php echo $data['nama_karyawan'] ?></option><?php } ?>
            </select>
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label">Tanggal Peminjaman</label>
          <div class="col-sm-7">
            <input type="date" class="form-control" name="tgl_pinjam" autocomplete="off" required value="<?php echo $tgl_pinjam; ?>">
          </div>
        </div>
       <div class="form-group">
          <label class="col-sm-3 control-label" >Kategori</label>
          <div class="col-sm-7">
          <select class="form-control chosen-select" name="id_kategori" onchange="javascript:submitform();"  >
                            <option value="Kosong">....</option>
                          <?php
      // Skrip menampilkan data Kategori ke ComboBo (ListMenu)
    $bacaSql = "SELECT * FROM kategori ORDER BY id_kategori";
    $bacaQry = mysql_query($bacaSql);
    while ($bacaData = mysql_fetch_array($bacaQry)) {
    if ($bacaData['id_kategori'] == $dataKategori)
      {
      $cek = "selected";
    } else { $cek=""; }
    echo "<option value='$bacaData[id_kategori]' $cek> $bacaData[nm_kategori]</option>";
    }
    ?> </select>

                         </div>
                     </div>
        <div class="form-group">
          <label class="col-sm-3 control-label" >Nama Barang</label>
          <div class="col-sm-7">
          <select class="form-control chosen-select" name="kd_brg"  data-placeholder="-- Pilih Kategori--" required  >
                           <option value=""></option>
                          <?php
                          $sql=mysql_query("select barang.kd_brg,gudang.nm_barang from barang inner join gudang on barang.id_brg_msk=gudang.id_brg_msk where id_kategori='$dataKategori' ORDER BY kd_brg");
                            while ($bacaData = mysql_fetch_array($sql)) {
                              if ($bacaData['kd_brg'] == $data)
                                {
                                  $cek = " selected";
                                } else { $cek=""; }
                                echo "<option value='$bacaData[kd_brg]' $cek> $bacaData[kd_brg] - $bacaData[nm_barang] </option>"; } ?>  </select>
                         </div>
                     </div>
        <div class="form-group">
          <label class="col-sm-3 control-label">Lokasi Proyek</label>
          <div class="col-sm-7">
            <input type="text" name="lokasi" class="form-control" maxlength="64"  placeholder="Lokasi Proyek" required value="<?php echo $lokasi; ?>">
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label">Keterangan</label>
          <div class="col-sm-7">
            <textarea name="ket" class="form-control" placeholder="Ket" required><?php echo $ket; ?>
            </textarea>
            <input name="btnTambah" type="submit" style="cursor:pointer;" value=" Tambah " />
          </div>
        </div>
        <div class="form-group">
          <label class="col-sm-3 control-label"> Daftar Barang</label>
          <div class="col-sm-7">
           <table  id="example2"  class="display nowrap" cellspacing="0" width="100%">
                      <thead>
                          <th>Kode Barang</th>
                          <th>Nama Barang</th>
                          <th>harga</th>
                          <th>Kondisi</th>
                          <th>Action</th>
                      </thead>
                      <tbody>
                       <?php
                       $sql =mysql_query("select tmp.*, barang.kd_brg, barang.kondisi, gudang.nm_barang FROM peminjaman_tmp As tmp
      JOIN barang ON tmp.kd_brg = barang.kd_brg LEFT JOIN gudang on barang.id_brg_msk=gudang.id_brg_msk
      WHERE tmp.id_user='$username' ORDER BY id"
                      );
                      $nomor=0;
                     while($row=mysql_fetch_array($sql)) {
                       $nomor++;
                       $id =  $row['id'];
                       ?>
        <tr>
          <td><?php echo $nomor; ?></td>
          <td><?php echo $row['kd_brg']; ?></td>
          <td><?php echo $row['nm_barang']; ?></td>
          <td><?php echo $row['kondisi']; ?></td>
          <td><a href="?Aksi=Hapus&id=<?php echo $id; ?>" target="_self">Delete</a></td>

        </tr>
        <?php } ?>
      </table></td>
    </tr>
      <div class="form-group" style="margin-bottom: 20px;">
        <label class="col-sm-4 col-sm-4 control-label"></label>
          <div class="col-sm-6">
        <input name="btnSimpan" type="submit" style="cursor:pointer;" value=" SIMPAN TRANSAKSI " />
          </div>
      </div>
      </tbody></table>
      </form>
    </div>
  </div>
</div>
<script>
  $(function () {
    $('#example2').DataTable({
      "paging": true,
      "ordering": true,
      "scrollX":true
    });
  });
</script>
avatar nurjanah1234
@nurjanah1234

5 Kontribusi 0 Poin

Dipost 7 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban