Nomor 1
Jawaban soal nomor 1:
tempelkan kode berikut pada file hapus.php:
<?php $kode = $_GET["kode"]; if ($kode<>"") { $query = $koneksi->query("DELETE FROM barang WHERE KdBrg='$kode' "); }?>tempelkan kode berikut pada file tampil.php:
<?php $query = $koneksi->query("SELECT * FROM barang"); $i = 1;?><h1>Tampil Data Barang</h1><table border=1> <tr> <td>No</td> <td>Kode Barang</td> <td>Nama Barang</td> <td>Harga</td> <td>Aksi</td> </tr> <?php while ($data = $query->fetch_array()) { $kode = $data['KdBrg']; echo " <tr> <td>" . $i++ . "</td> <td>" . $data['KdBrg'] . "</td> <td>" . $data['NmBrg'] . "</td> <td>Rp." . number_format($data['Harga'],0,",",".") . ",-</td> <td>Ubah | <a href='index.php?hal=hapus.php&kode=$kode'>Hapus</a> </td> </tr>"; } ?></table>