Membuat Aplikasi Website CRUD Sederhana dengan PHP dan MySQL - Bagian 2

10:11
Setelah membuat database dan membuat koneksinya, lanjut ke langkah selanjutnya.

Langkah 3 # Menampilkan Data (R)
Buatlah sebuah file dengan nama tampil_data.php
  <?php
  include 'koneksi.php';
  $readtabel = mysql_query("SELECT * FROM buku ORDER BY kode");
  ?>
  <!DOCTYPE html>
  <html>
  <head>
  <title>Belajar CRUD PHP - Read</title>
  </head>
  <body>
  <h1>Menampilkan data dari database - Read</h1>
  <hr>
  <a href="input_data.php" title="Tambah Data"
 style="text-decoration:none; border:1px #000 solid;
 background-color: green; color:#000; padding: 5px 15px;
 text-align:center;">Tambah Data</a>
  <hr>
  <table border="1" cellspacing="0" cellpadding="2">
  <caption>Data Buku</caption>
  <thead>
  <tr>
  <th>No</th>
  <th>Kode Buku</th>
  <th>Judul Buku</th>
  <th>Tahun Terbit</th>
  <th>Harga</th>
  <th></th>
  </tr>
  </thead>
  <tbody>
  <?php 
  $no = 1;
  while ($getdata = mysql_fetch_array($readtabel)) { 
  ?>
  <tr>
  <td><?php echo $no++ ?></td>
  <td><?php echo $getdata['kode'] ?></td>
  <td><?php echo $getdata['judul'] ?></td>
  <td><?php echo $getdata['tahun'] ?></td>
  <td>Rp. <?php echo $getdata['harga'] ?>,00</td>
  <td>
  <a href="update_data.php?kode=<?php echo $getdata['kode'] ?>"
 title="Update">Update</a> | 
  <a href="hapus_data.php?kode=<?php echo $getdata['kode'] ?>"
 title="Hapus"
 onclick="return confirm('Hapus buku ini?')">Hapus</a>
  </td>
  </tr>
  <?php } ?>
  </tbody>
  </table>
  </body>
  </html>


Jika sudah, cek pada browser, jika benar maka tampil sbb :

Membuat Aplikasi Website CRUD Sederhana dengan PHP dan MySQL - tampil


Langkah 4 # Menyimpan (Menambah) Data (C)
Buatlah file input_data.php
<!DOCTYPE html>
<html>
<head>
<title>Belajar CRUD PHP - Create</title>
</head>
<body>
<form action="simpan_data.php" method="post">
<table>
<tr>
<td width="150">Kode</td>
<td width="300">
<input type="text" name="kode" value="" placeholder="Kode" size="15">
</td>
</tr>
<tr>
<td>Judul Buku</td>
<td><input type="text" name="judul" placeholder="Judul Buku"></td>
</tr>
<tr>
<td>Tahun Terbit</td>
<td><input type="text" name="tahun" ></td>
</tr>
<tr>
<td>Harga Buku</td>
<td><input type="text" name="harga" ></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="simpan" value="Simpan">
<input type="reset" name="reset" value="Ulang">
</td>
</tr>
</table>
</form>
</body>
</html>

Jika sudah, cek pada browser, jika benar maka tampil sbb :

Membuat Aplikasi Website CRUD Sederhana dengan PHP dan MySQL - input


Untuk Lihat Tutorial bagian 1 kunjungi tautan berikut
Membuat Aplikasi Website CRUD Sederhana dengan PHP dan MySQL - Bagian 1

Lanjut ke Bagian 3, kunjungi tautan berikut
Membuat Aplikasi Website CRUD Sederhana dengan PHP dan MySQL - Bagian 3

Share this :

Previous
Next Post »
0 Komentar