Thursday, October 5, 2017

√ Menciptakan Pinjam Buku Dengan Php Mysql

Tutorial Membuat Sistem peminjaman/pengembalian buku Berbasi PHP & Mysql ini saya buat atas request teman-teman untuk melanjutkan postingan saya ihwal pemrograman Sederhana Menggunakan PHP.

sepakat yang perlu kalian siapkan yaitu kalian WAJIB Download & Menginstall :

  • Notepad ++ dan 
  • Xampp Control Panel pada komputer kalian. 
saya rasa kau sudah menginstal kedua aplikasi tersebut pada komputer.

semua file baik dari Script php maupun database sudah saya lampirkan pada bab final artikel. kalau anda mempunyai pertanyaan silahkan bertanya pada kolom komentar.


#1 Tampilan APlikasi Pinjam/Kembali Buku yang akan saya buat ibarat Berikut

FAsilitas sederhana dari apkikasi pinjam buku dengan php mysql diatas yaitu :

  • pada sajian anggota/member diatas, menyediakan kemudahan input anggota/member baru, edit dan delete.
  • pada sajian Buku diatas, menyediakan kemudahan input Buku baru, edit dan delete.
  • pada menu Pinjam diatas, menyediakan kemudahan peminjaman buku, edit dan delete. serta akan terlihat tgl pinjam dan kapan buku tersebut akan dikembali


#2 Cara menciptakan "DataBase" dan "Tabel"


  •  jalankan aplikasi xampp klik start Apache dan Mysql ibarat berikut 
  • buka browser Chrome/Mozilla, kemudian ketikkan localhost/phpmyadmin kemudian buat 


database dengan nama : databuku
table dengan nama : anggota
table dengan nama : buku
table dengan nama : meminjam
sehingga menjadi ibarat berikut ini :
kemudian untuk struktur dan type data masing-masing tabel yaitu sebagai berikut :

Struktur Tabel "anggota" :

Struktur Tabel "buku" :

Struktur Tabel "meminjam" :


#3 Script Program


  • Silahkan kalian Copy-Paste di Notpad++ dan berikan nama ibarat berikut ini : (dalam penyimpanan Script PHP nama jangan hingga salah, alasannya dapat menimbulkan eror)
  • Semua file .php harap kau masukkan di dalam Local Disk C==>xampp==>htdocs==>lalu buat folder dengan nama pinjambuku



koneksi.php


file koneksi.php ini dipakai untuk konek ke database "databuku"
<?php 
$servername = "localhost";
$user  = "root";
$pasword = "";
$db   = "databuku";

$koneksi = mysql_connect ($servername,$user, $pasword)
   or die ('gagal terkoneksi'.mysql_error());
  
$database = mysql_select_db ($db)
   or die ('gagal terhubung ke database'.mysql_error());
?>



anggota.php


file anggota.php ini dipakai untuk mendata/menyimpan anggota dan peminjaman buku
<html>
<head>
</head>
<body>
<table width="1000" border="1">
<tr>
<td colspan="2" align="center"><h1>Peminjaman dan pengembalian buku php & mysql</h1></td>
</tr>
<tr>
<td width = "200">
<ul>
<li><a href="anggota.php">Anggota/member</a></li>
<li><a href="buku.php">Buku</a></li>
<li><a href="pinjam.php">Pinjam</a></li>
<ul>

</td>
<td width="500">
<a href="input_anggota.php">Input anggota</a>
 <table border="1" >
                                        <thead>

          <tr>
            <th >No</th>
            <th >id_anggota </th>
   <th >nama anggota </th>
   <th >alamat </th>
   <th >TTl </th>
   <th >Status</th>
  
   <th >Aksi</th>
          </tr>
        </thead>
                                    <tbody>
         <?php 
include "koneksi.php";
$query = "select * from anggota order by id_anggota";
$sql = mysql_query ($query);
$no = 1;
while ($data=mysql_fetch_array($sql)) {
?>  
                                        <tr class="odd gradeX">
                                            <td><?php echo $no?></td>
                                            <td><?php echo $data['id_anggota'];?></td>
            <td><?php echo $data['nm_anggota'];?></td>
             <td><?php echo $data['alamat'];?></td>
              <td><?php echo $data['ttl_anggota'];?></td>
               <td class="center"><?php echo $data['status_anggota'];?></td>
          
                                            <td class="center"><a href="edit_anggota.php?id=<?php echo $data['id_anggota']; ?>" > Edit </a>|<a href="hapus_anggota.php?id=<?php echo $data['id_anggota']; ?>" 
 onClick = "return confirm('Apakah Anda ingin mengapus  <?php echo $data['nm_anggota']; ?>?')"> hapus</a></td>
                                        </tr>
         
                                        <?php $no++; }?>
                                    </tbody>

                                </table>
</td>
</tr>
<tr>
<td colspan="2" align="center">sharingse<br><script type='text/j4vascript' src='//eclkmpsa.com/adServe/banners?tid=94091_154020_0&tagid=2'></script> <br> <script type='text/j4vascript' src='//eclkmpbn.com/adServe/banners?tid=94091_154020_2'></script></td>
</tr>
</table>
</body>
</html>



buku.php


file buku.php ini dipakai untuk menyimpan data buku ke database
<html>
<head>
</head>
<body>
<table width="1000" border="1">
<tr>
<td colspan="2" align="center"><h1>Peminjaman dan pengembalian buku php & mysql</h1></td>
</tr>
<tr>
<td width = "200">
<ul>
<li><a href="anggota.php">Anggota/member</a></li>
<li><a href="buku.php">Buku</a></li>
<li><a href="pinjam.php">Pinjam</a></li>
<ul>

</td>
<td width="500">
<a href="input_buku.php">Input buku</a>
 <table border="1" >
                                        <thead>
          <tr>
            <th >No</th>
            <th >Kode Buku </th>
   <th >Judul Buku </th>
   <th >Pengarang </th>
   <th >jenis Buku</th>
   <th >penerbit</th>
  
   <th >Aksi</th>
          </tr>
        </thead>
                                    <tbody>
         <?php 
include "koneksi.php";
$query = "select * from buku order by kd_buku";
$sql = mysql_query ($query);
$no = 1;
while ($data=mysql_fetch_array($sql)) {
?>  
                                        <tr class="odd gradeX">
                                            <td><?php echo $no?></td>
                                            <td><?php echo $data['kd_buku'];?></td>
            <td><?php echo $data['judul_buku'];?></td>
             <td><?php echo $data['pengarang'];?></td>
              <td><?php echo $data['jenis_buku'];?></td>
               <td class="center"><?php echo $data['penerbit'];?></td>
           
                                            <td class="center"><a href="edit_buku.php?id=<?php echo $data['kd_buku']; ?>" > Edit </a>|<a href="hapus_buku.php?id=<?php echo $data['kd_buku']; ?>" 
 onClick = "return confirm('Apakah Anda ingin mengapus  <?php echo $data['judul_buku']; ?>?')"> hapus</a></td>
                                        </tr>
         
                                        <?php $no++; }?>
                                    </tbody>

                                </table>
</td>
</tr>
<tr>
<td colspan="2" align="center">sharingse<br><script type='text/j4vascript' src='//eclkmpsa.com/adServe/banners?tid=94091_154020_0&tagid=2'></script> <br> <script type='text/j4vascript' src='//eclkmpbn.com/adServe/banners?tid=94091_154020_2'></script></td>
</tr>
</table>
</body>
</html>


edit_anggota.php


file edit_anggota.php ini dipakai untuk mengedit data yang ada di dalam database
<html>
<head>
</head>
<body>
<?php 
include "koneksi.php";
?>
<table width="700" border="1">
<tr>
<td colspan="2" align="center"><h1>Peminjaman dan pengembalian buku php & mysql</h1></td>
</tr>
<tr>
<td width = "200">
<ul>
<li><a href="anggota.php">Anggota/member</a></li>
<li><a href="buku.php">Buku</a></li>
<li><a href="pinjam.php">Pinjam</a></li>
<ul>

</td>
<td width="500">
<form method="post" action="proses_edit_anggota.php?id=<?php echo $_GET['id'];?>" >

<?php 
$id = $_GET['id'];
$query = mysql_query ("select * from anggota where id_anggota=$id");
$data= mysql_fetch_array($query);
?>

<table border="0">
<tr>
<td>nama anggota</td>
<td>:</td>
<td><input type="text" name="nama"  value="<?php echo $data['nm_anggota']?>"></td>
</tr>
<tr>
<td>Alamat</td>
<td>:</td>
<td><textarea name="alamat"  ><?php echo $data['alamat']?></textarea></td>
</tr>
<tr>
<td>TGL lahir</td>
<td>:</td>
<td><textarea name="ttl"  ><?php echo $data['ttl_anggota']?></textarea></td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td><select name="status">
<option value="1">aktif</option>
<option value="2">tidak aktif</option>
</select></td>
</tr>
<tr>
<td></td>
<td></td>
<td><input type="submit" name="simpan" value="simpan"></td>
</tr>

</table>
</form>
</td>
</tr>
<tr>
<td colspan="2" align="center">sharingse<br><script type='text/j4vascript' src='//eclkmpsa.com/adServe/banners?tid=94091_154020_0&tagid=2'></script> <br> <script type='text/j4vascript' src='//eclkmpbn.com/adServe/banners?tid=94091_154020_2'></script></td>
</tr>
</table>

</body>
</html>


edit_buku.php


file edit_buku.php ini dipakai untuk mengedit data buku yang ada di dalam database
<html>
<head>
</head>
<body>
<?php 
include "koneksi.php";
?>
<table width="700" border="1">
<tr>
<td colspan="2" align="center"><h1>Selamat Datang Di Sistem Perpustakaan</h1></td>
</tr>
<tr>
<td width = "200">
<ul>
<li><a href="anggota.php">Anggota/member</a></li>
<li><a href="buku.php">Buku</a></li>
<li><a href="pinjam.php">Pinjam</a></li>
<ul>

</td>
<td width="500">
<form method="post" action="proses_edit_buku.php?id=<?php echo $_GET['id'];?>" >

<?php 
$id = $_GET['id'];
$query = mysql_query ("select * from buku where kd_buku=$id");
$data= mysql_fetch_array($query);
?>

<table border="0">
<tr>
<td>Kode Buku</td>
<td>:</td>
<td><input type="text" name="kode"  value="<?php echo $data['kd_buku']?>"></td>
</tr>
<tr>
<td>Judul Buku</td>
<td>:</td>
<td><input type="text" name="judul"  value="<?php echo $data['judul_buku']?>"></td>
</tr>
<tr>
<td>Pengarang</td>
<td>:</td>
<td><input type="text" name="pengarang"  value="<?php echo $data['pengarang']?>"></td>
</tr>
<tr>
<td>Jenis Buku</td>
<td>:</td>
<td><input type="text" name="jenis"  value="<?php echo $data['jenis_buku']?>">
</tr>
<tr>
<td>Penerbit Buku</td>
<td>:</td>
<td><input type="text" name="penerbit"  value="<?php echo $data['penerbit']?>">
</tr>
<tr>
<td></td>
<td></td>
<td><input type="submit" name="simpan" value="simpan"></td>
</tr>

</table>
</form>
</td>
</tr>
<tr>
<td colspan="2" align="center">sharingse<br><script type='text/j4vascript' src='//eclkmpsa.com/adServe/banners?tid=94091_154020_0&tagid=2'></script> <br> <script type='text/j4vascript' src='//eclkmpbn.com/adServe/banners?tid=94091_154020_2'></script></td>
</tr>
</table>

</body>
</html>


edit_pinjam.php


file edit_pinjam.php ini dipakai untuk mengedit data peminjaman buku yang ada di dalam database
<html>
<head>
</head>
<body>
<?php 
include "koneksi.php";
?>
<table width="700" border="1">
<tr>
<td colspan="2" align="center"><h1>Selamat Datang Di Sistem Perpustakaan</h1></td>
</tr>
<tr>
<td width = "200">
<ul>
<li><a href="anggota.php">Anggota/member</a></li>
<li><a href="buku.php">Buku</a></li>
<li><a href="pinjam.php">Pinjam</a></li>
<ul>

</td>
<td width="500">
<form method="post" action="proses_edit_pinjam.php?id=<?php echo $_GET['id'];?>" >

<?php 
$id = $_GET['id'];
$query = mysql_query ("select * from meminjam where id_pinjam=$id");
$data= mysql_fetch_array($query);
?>

<table border="0">
<tr>
<td>Nama Peminjam</td>
<td>:</td>
<td><?php

$sql_anggota="select * from anggota order by id_anggota";
$kueri_anggota=mysql_query($sql_anggota) or die(mysql_error());
?>
                                            <select name="anggota">
                                             <?php
 while (list($kode,$nama_status)=mysql_fetch_array($kueri_anggota))
   {
?>
      <option  value="<?php echo $kode ?>"><?php echo $nama_status ?></option>
<?php
  }
?>
                                            </select></td>
</tr>
<tr>
<td>Judul Buku </td>
<td>:</td>
<td><?php

$sql_buku="select * from buku order by kd_buku";
$kueri_buku=mysql_query($sql_buku) or die(mysql_error());
?>
                                            <select name="buku">
                                             <?php
 while (list($kode,$nama_status)=mysql_fetch_array($kueri_buku))
   {
?>
      <option  value="<?php echo $kode ?>"><?php echo $nama_status ?></option>
<?php
  }
?>
                                            </select><td>
</tr>          
          
<tr>
<td></td>
<td></td>
<td><input type="submit" name="simpan" value="simpan"></td>
</tr>

</table>
</form>
</td>
</tr>
<tr>
<td colspan="2" align="center">sharingse<br><script type='text/j4vascript' src='//eclkmpsa.com/adServe/banners?tid=94091_154020_0&tagid=2'></script> <br> <script type='text/j4vascript' src='//eclkmpbn.com/adServe/banners?tid=94091_154020_2'></script></td>
</tr>
</table>

</body>
</html>


hapus_anggota.php


file hapus_anggota.php ini dipakai untuk menghapus anggota yang ada di dalam database
<?php
include "koneksi.php";
$id = $_GET['id'];

$query = mysql_query("delete from anggota where id_anggota='$id'");
if ($query) {
echo "<script>alert('data berhasil dihapus');
document.location.href='anggota.php'</script>\n";
} else {
echo "<script>alert('data gagal dihapus');
document.location.href='anggota.php'</script>\n";
}
?>


hapus_buku.php


file hapus_buku.php ini dipakai untuk menghapus data buku yang ada di dalam database
<?php
include "koneksi.php";

$id = $_GET['id'];

$query = mysql_query("delete from buku where kd_buku='$id'");
if ($query) {
echo "<script>alert('data berhasil dihapus');
document.location.href='buku.php'</script>\n";
} else {
echo "<script>alert('data gagal dihapus');
document.location.href='buku.php'</script>\n";
}
?>


hapus_pinjam.php


file hapus_pinjam.php ini dipakai untuk menghapus data peminjam buku yang ada di dalam database
<?php
include "koneksi.php";

$id = $_GET['id'];

$query = mysql_query("delete from meminjam where id_pinjam='$id'");
if ($query) {
echo "<script>alert('data berhasil dihapus');
document.location.href='pinjam.php'</script>\n";
} else {
echo "<script>alert('data gagal dihapus');
document.location.href='pinjam.php'</script>\n";
}
?>


index.php


file index.php ini dipakai untuk menampilkan halaman awal aplikasi
<html>
<head>
</head>
<body>
<table width="700" border="1">
<tr>
<td colspan="2" align="center"><h1>Peminjaman dan pengembalian buku php & mysql</h1> <br><script type='text/j4vascript' src='//eclkmpsa.com/adServe/banners?tid=94091_154020_0&tagid=2'></script> <br> <script type='text/j4vascript' src='//eclkmpbn.com/adServe/banners?tid=94091_154020_2'></script></td>
</tr>
<tr>
<td width = "200">
<ul>
<li><a href="anggota.php">Anggota/Member</a></li>
<li><a href="buku.php">Buku</a></li>
<li><a href="pinjam.php">Pinjam</a></li>
<ul>

</td>
<td width="500">pada script ini sudah saya sederhanakan, ada isu tgl pinjam dan tgl kembali, serta denda bagi yang telat mengembalikan</td>
</tr>
<tr>
<td colspan="2" align="center"><a href="https://sharingse.blogspot.co.id">Sharingse || kumpulan software gratis dan pemrograman || mencar ilmu dengan gampang || kalau ada pertanyaan silahkan pribadi hubungi saya, siapa tahu saya dapat bantu kalian</a></td>
</tr>
</table>
</body>
</html>


input_anggota.php


file input_anggota .php ini dipakai untuk menginputkan data anggota ke dalam database
<html>
<head>
</head>
<body>
<table width="700" border="1">
<tr>
<td colspan="2" align="center"><h1>Selamat Datang Di Sistem Perpustakaan</h1></td>
</tr>
<tr>
<td width = "200">
<ul>
<li><a href="anggota.php">Anggota/member</a></li>
<li><a href="buku.php">Buku</a></li>
<li><a href="pinjam.php">Pinjam</a></li>
<ul>

</td>
<td width="500">
<form method="post" action="proses.php" >
<table border="0">
<tr>
<td>nama anggota</td>
<td>:</td>
<td><input type="text" name="nama"  placeholder="Nama"></td>
</tr>
<tr>
<td>Alamat</td>
<td>:</td>
<td><textarea name="alamat" placeholder="Alamat" ></textarea></td>
</tr>
<tr>
<td>ttl</td>
<td>:</td>
<td><textarea name="ttl" placeholder="Tempat tanggal lahir" ></textarea></td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td><select name="status">
<option value="1">aktif</option>
<option value="2">tidak aktif</option>
</select></td>
</tr>
<tr>
<td></td>
<td></td>
<td><input type="submit" name="simpan" value="simpan"></td>
</tr>

</table>
</form>
</td>
</tr>
<tr>
<td colspan="2" align="center">sharingse<br><script type='text/j4vascript' src='//eclkmpsa.com/adServe/banners?tid=94091_154020_0&tagid=2'></script> <br> <script type='text/j4vascript' src='//eclkmpbn.com/adServe/banners?tid=94091_154020_2'></script></td>
</tr>
</table>
</body>
</html>


input_buku.php


file input_buku.php ini dipakai untuk menginputkan data buku ke dalam database
<html>
<head>
</head>
<body>
<table width="700" border="1">
<tr>
<td colspan="2" align="center"><h1>Peminjaman dan pengembalian buku php & mysql</h1></td>
</tr>
<tr>
<td width = "200">
<ul>
<li><a href="anggota.php">Anggota/member</a></li>
<li><a href="buku.php">Buku</a></li>
<li><a href="pinjam.php">Pinjam</a></li>
<ul>

</td>
<td width="500">
<form method="post" action="proses_buku.php" >
<table border="0">
<tr>
<td>Kode Buku</td>
<td>:</td>
<td><input type="text" name="kode"  placeholder="Kode Buku"></td>
</tr>
<tr>
<td>Judul Buku</td>
<td>:</td>
<td><input type="text" name="judul"  placeholder="Judul Buku"></td>
</tr>
<tr>
<td>Pengarang</td>
<td>:</td>
<td><input type="text" name="pengarang"  placeholder="Pengarang Buku"></td>
</tr>
<tr>
<td>Jenis Buku</td>
<td>:</td>
<td><input type="text" name="jenis"  placeholder="Jenis Buku">
</tr>
<tr>
<td>Penerbit Buku</td>
<td>:</td>
<td><input type="text" name="penerbit"  placeholder="Penerbit Buku">
</tr>
<tr>
<td></td>
<td></td>
<td><input type="submit" name="simpan" value="simpan"></td>
</tr>

</table>
</form>
</td>
</tr>
<tr>
<td colspan="2" align="center">sharingse<br><script type='text/j4vascript' src='//eclkmpsa.com/adServe/banners?tid=94091_154020_0&tagid=2'></script> <br> <script type='text/j4vascript' src='//eclkmpbn.com/adServe/banners?tid=94091_154020_2'></script></td>
</tr>
</table>
</body>
</html>


kembali_buku.php


file kembali_buku.php ini dipakai untuk siapa yang sudah mengembalian buku 
<?php
include "koneksi.php";

$tgl = date('Y-m-d');

$query = mysql_query("UPDATE meminjam SET tgl_kembali  = '$tgl', kembali = '2'
          where id_pinjam ='$_GET[id]'");
if ($query) {
echo "<script>alert('Buku Sudah Dikembalikan');
document.location.href='pinjam.php'</script>\n";
} else {
echo "<script>alert('gagal');
document.location.href='pinjam.php'</script>\n";
}
?>


pinjam.php

<html>
<head>
</head>
<body>
<table width="1000" border="1">
<tr>
<td colspan="2" align="center"><h1>Peminjaman dan pengembalian buku php & mysql</h1></td>
</tr>
<tr>
<td width = "200">
<ul>
<li><a href="anggota.php">Anggota/member</a></li>
<li><a href="buku.php">Buku</a></li>
<li><a href="pinjam.php">Pinjam</a></li>
<ul>

</td>
<td width="500">
<a href="pinjam_buku.php">Pinjam buku</a>
<p>buku yang sedang dipinjam  </p>
 <table border="1" >
                                        <thead>
          <tr>
            <th >No</th>
            <th >Tanggal Pinjam Buku </th>
   <th >Jumlah Pinjam </th>
   <th >tanggal kembali </th>
   <th >nama peminjam</th>
   <th >Buku</th>
  
   <th >Aksi</th>
          </tr>
        </thead>
                                    <tbody>
         <?php 
include "koneksi.php";
$query = "select * from meminjam,buku,anggota
where meminjam.id_anggota = anggota.id_anggota and
meminjam.kd_buku = buku.kd_buku and meminjam.kembali = 1
 order by id_pinjam";
$sql = mysql_query ($query);
$no = 1;
while ($data=mysql_fetch_array($sql)) {
?>  
                                        <tr class="odd gradeX">
                                            <td><?php echo $no?></td>
                                            <td><?php echo $data['tgl_pinjam'];?></td>
            <td><?php echo $data['jumlah_pinjam'];?></td>
             <td><?php echo $data['tgl_kembali'];?></td>
              <td><?php echo $data['nm_anggota'];?></td>
               <td class="center"><?php echo $data['judul_buku'];?></td>
          
                                            <td class="center"><a href="edit_pinjam.php?id=<?php echo $data['id_pinjam']; ?>" > Edit </a> | <a href="kembali_buku.php?id=<?php echo $data['id_pinjam']; ?>" onClick = "return confirm('Apakah Anda ingin mengembalikan  <?php echo $data['judul_buku']; ?>?')"> Kembalikan </a></td>
                                        </tr>   
                                        <?php $no++; }?>
                                    </tbody>

                                </table>
        <br>
       
        <p>buku yang sudah di kembalikan  </p>
         <table border="1" >
                                        <thead>
          <tr>
            <th >No</th>
            <th >Tanggal Pinjam Buku </th>
   <th >Jumlah Pinjam </th>
   <th >tanggal kembali </th>
   <th >nama peminjam</th>
   <th >Buku</th>
  
   <th >Aksi</th>
          </tr>
        </thead>
                                    <tbody>
         <?php 
include "koneksi.php";
$query = "select * from meminjam,buku,anggota
where meminjam.id_anggota = anggota.id_anggota and
meminjam.kd_buku = buku.kd_buku and meminjam.kembali = 2
 order by id_pinjam";
$sql = mysql_query ($query);
$no = 1;
while ($data=mysql_fetch_array($sql)) {
?>  
                                        <tr class="odd gradeX">
                                            <td><?php echo $no?></td>
                                            <td><?php echo $data['tgl_pinjam'];?></td>
            <td><?php echo $data['jumlah_pinjam'];?></td>
             <td><?php echo $data['tgl_kembali'];?></td>
              <td><?php echo $data['nm_anggota'];?></td>
               <td class="center"><?php echo $data['judul_buku'];?></td>
          
                                            <td class="center"><a href="hapus_pinjam.php?id=<?php echo $data['id_pinjam']; ?>" 
 onClick = "return confirm('Apakah Anda ingin mengapus  <?php echo $data['id_pinjam']; ?>?')"> hapus</a> </td>
                                        </tr>
         
                                        <?php $no++; }?>
                                    </tbody>

                                </table>
</td>
</tr>
<tr>
<td colspan="2" align="center">sharingse<br><script type='text/j4vascript' src='//eclkmpsa.com/adServe/banners?tid=94091_154020_0&tagid=2'></script> <br> <script type='text/j4vascript' src='//eclkmpbn.com/adServe/banners?tid=94091_154020_2'></script></td>
</tr>
</table>
</body>
</html>


pinjam_buku.php


<html>
<head>
</head>
<body>
<table width="700" border="1">
<tr>
<td colspan="2" align="center"><h1>Peminjaman dan pengembalian buku php & mysql</h1></td>
</tr>
<tr>
<td width = "200">
<ul>
<li><a href="anggota.php">Anggota/member</a></li>
<li><a href="buku.php">Buku</a></li>
<li><a href="pinjam.php">Pinjam</a></li>
<ul>

</td>
<td width="500">
<?php include "koneksi.php";?>
<form method="post" action="proses_pinjam.php" >
<table border="0">
<tr>
<td>Nama Peminjam</td>
<td>:</td>
<td><?php

$sql_anggota="select * from anggota order by id_anggota";
$kueri_anggota=mysql_query($sql_anggota) or die(mysql_error());
?>
                                            <select name="anggota">
                                             <?php
 while (list($kode,$nama_status)=mysql_fetch_array($kueri_anggota))
   {
?>
      <option  value="<?php echo $kode ?>"><?php echo $nama_status ?></option>
<?php
  }
?>
                                            </select></td>
</tr>
<tr>
<td>Judul Buku </td>
<td>:</td>
<td><?php

$sql_buku="select * from buku order by kd_buku";
$kueri_buku=mysql_query($sql_buku) or die(mysql_error());
?>
                                            <select name="buku">
                                             <?php
 while (list($kode,$nama_status)=mysql_fetch_array($kueri_buku))
   {
?>
      <option  value="<?php echo $kode ?>"><?php echo $nama_status ?></option>
<?php
  }
?>
                                            </select><td>
</tr>          
<tr>
<td></td>
<td></td>
<td><input type="submit" name="simpan" value="simpan"></td>
</tr>

</table>
</form>
</td>
</tr>
<tr>
<td colspan="2" align="center">sharingse<br><script type='text/j4vascript' src='//eclkmpsa.com/adServe/banners?tid=94091_154020_0&tagid=2'></script> <br> <script type='text/j4vascript' src='//eclkmpbn.com/adServe/banners?tid=94091_154020_2'></script></td>
</tr>
</table>
</body>
</html>


proses.php


<?php
include "koneksi.php";

$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$ttl = $_POST['ttl'];
$status = $_POST['status'];

$query = mysql_query('insert into anggota(nm_anggota,alamat,ttl_anggota,status_anggota) values ("'.$nama.'","'.$alamat.'","'.$ttl.'","'.$status.'")');
if ($query) {
echo "<script>alert('data berhasil disimpan');
document.location.href='anggota.php'</script>\n";
} else {
echo "<script>alert('data gagal disimpan');
document.location.href='input_anggota.php'</script>\n";
}
?>


proses_buku.php


<?php
include "koneksi.php";

$kode  = $_POST['kode'];
$judul  = $_POST['judul'];
$pengarang = $_POST['pengarang'];
$jenis  = $_POST['jenis'];
$penerbit = $_POST['penerbit'];


$query = mysql_query('insert into buku(kd_buku,judul_buku,pengarang,jenis_buku,penerbit) values ("'.$kode.'","'.$judul.'","'.$pengarang.'","'.$jenis.'","'.$penerbit.'")');
if ($query) {
echo "<script>alert('data berhasil disimpan');
document.location.href='buku.php'</script>\n";
} else {
echo "<script>alert('data gagal disimpan');
document.location.href='input_buku.php'</script>\n";
}
?>


proses_edit_anggota.php


<?php
include "koneksi.php";

$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$ttl = $_POST['ttl'];
$status = $_POST['status'];

$query = mysql_query("UPDATE anggota SET nm_anggota  ='$nama',
          alamat   ='$alamat',
          ttl_anggota  ='$ttl',
          status_anggota ='$status' 
          where id_anggota  ='$_GET[id]'");
if ($query) {
echo "<script>alert('data berhasil disimpan');
document.location.href='anggota.php'</script>\n";
} else {
echo "<script>alert('data gagal disimpan');
document.location.href='anggota.php'</script>\n";
}
?>


proses_edit_buku.php


<?php
include "koneksi.php";

$kode  = $_POST['kode'];
$judul  = $_POST['judul'];
$pengarang = $_POST['pengarang'];
$jenis  = $_POST['jenis'];
$penerbit = $_POST['penerbit'];

$query = mysql_query("UPDATE buku SET  kd_buku   ='$kode',
          judul_buku  ='$judul',
          pengarang  ='$pengarang',
          jenis_buku  ='$jenis',
          penerbit  ='$penerbit' 
          where kd_buku ='$_GET[id]'");
if ($query) {
echo "<script>alert('data berhasil disimpan');
document.location.href='buku.php'</script>\n";
} else {
echo "<script>alert('data gagal disimpan');
document.location.href='buku.php'</script>\n";
}
?>


proses_edit_pinjam.php


<?php
include "koneksi.php";

$anggota = $_POST['anggota'];
$buku  = $_POST['buku'];
$tgl = date('Y-m-d');

$query = mysql_query("UPDATE meminjam SET tgl_pinjam  ='$tgl',
          id_anggota   ='$anggota',
          kd_buku    ='$buku'
          where id_pinjam ='$_GET[id]'");
if ($query) {
echo "<script>alert('data berhasil disimpan');
document.location.href='pinjam.php'</script>\n";
} else {
echo "<script>alert('data gagal disimpan');
document.location.href='pinjam.php'</script>\n";
}
?>


proses_kembali_buku.php


<?php
include "koneksi.php";

$query = mysql_query("UPDATE meminjam SET tgl_kembali  ='date(Y-m-d)'
         
          where id_pinjam ='$_GET[id]'");
if ($query) {
echo "<script>alert('Buku Sudah Dikembalikan');
document.location.href='pinjam.php'</script>\n";
} else {
echo "<script>alert('gagal');
document.location.href='pinjam.php'</script>\n";
}
?>


proses_pinjam.php


<?php
include "koneksi.php";

$anggota = $_POST['anggota'];
$buku  = $_POST['buku'];

$query = mysql_query('insert into meminjam(tgl_pinjam,jumlah_pinjam,tgl_kembali,id_anggota,kd_buku,kembali) values ("'.date('Y-m-d').'",1,"'.$tgl_kembali.'","'.$anggota.'","'.$buku.'",1)');
if ($query) {
echo "<script>alert('data berhasil disimpan');
document.location.href='pinjam.php'</script>\n";
} else {
echo "<script>alert('data gagal disimpan');
document.location.href='pinjam.php'</script>\n";
}
?>


#Cara menjalankan Aplikasi pinjam buku dengan php mysql


sehabis semua  langkah-langkah diatassudah kau lakukan dengan benar kini silahkan jalankan programnya dengan cara :
  • pastikan aplikasi xampp control panelnya sudah start
  • buka browser mozilla/chrome
  • ketikkan localhost/pinjambuku
  • selesai


Sumber http://www.sharingse.net/