Nomor 2

Jawaban Soal Nomor 2 :


file baru css dengan nama "style.css" dan isi script

#simple {
    margin: 0;
    padding: 1;
    width: 125px;
}

#simple li {
    /*background: linear-gradient(-45deg, #0044a1, #005ddc);*/
    background: #a3a375;
    border-bottom: 1px solid #FFF;
    list-style: none;
    padding: 0.5em;
    text-align: center;
    width: 100px;
}

#simple li:hover {
    background: #0f0f0a;
}

#simple li a {
    color: white;
    display: block;
    text-decoration: none;
}
.tombol {
    border-color: red;
   color: white; 
   padding: 5px 10px;
   background: #000000;
   display: table;
}

Edit Script "index.php"

<?php
  error_reporting(~E_NOTICE); #ini digunakan utk menyembunyikan error khusus notice khususnya di index / beranda
 $koneksi = new mysqli("localhost", "root", "", "db_kk0918");
 if ($koneksi->connect_error) 
 {
  echo "Gagal terhubung karena " . $koneksi->connect_error;
 }
?>
<link rel="stylesheet" type="text/css" href="style.css">
<table border="1" width="80%" align="center">
 <tr align="center">
  <td colspan="2"><img src="images/header.png" height="64px" width="100%"></td>
 </tr>
 <tr>
  <td width="10%">
   <h3>Menu</h3>
   <ul id="simple">
       <li><a href="index.php">Beranda</a></li>
       <li><a href="index.php?hal=tentang.php">Tentang</a></li>
       <li><a href="index.php?hal=entry.php">Entry (C)</a></li>
       <li><a href="index.php?hal=tampil.php">Tampil (R)</a></li>
       <li><a href="index.php?hal=ubah.php">Ubah (U)</a></li>
       <li><a href="index.php?hal=hapus.php">Hapus (D)</a></li>

   </ul>

  </td>
  <td align="justify">
   <?php 
    $hal = $_GET["hal"]; #echo $_GET["hal"]; utk nampilin isi yang dari kita get/post dari index.php?hal=xxx.php
    if (isset($hal) && $hal!="")
    { #kondisi ini akan dijalankan jika variabel $hal digunakan dan variabel $hal  isinya bukan kosong
     include($hal); 
    }
    else
    {
     echo "<h1>Selamat Datang</h1><p>Saya datang dari Habang, jauh menuntut ilmu, biarlah yang penting saya bisa. Saya yakin pasti bisa <strong>#nekbisanekkawa</strong></p>";
    }
   ?>
  </td>
 </tr>
 <tr align="center">
  <td colspan="2" background="images/akbar.png">footer</td>
 </tr>
</table>

Edit Script "entry.php"

<link rel="stylesheet" type="text/css" href="style.css">
<form method="POST">
  <h1>Entry Data Barang</h1>
 <table>
  <tr>
   <td>Kode Barang :</td>
   <td><input type="text" name="txtKd"></td>
  </tr>
  <tr>
   <td>Nama Barang :</td>
   <td><input type="text" name="txtNm"></td>
  </tr>
  <tr>
   <td>Harga :</td>
   <td><input type="text" name="txtHr" onkeyup="this.value=this.value.replace(/[^\d]/,'')"></td>
  </tr>
  <tr>
   <td colspan="2">
    <input class="tombol" type="submit" value="Simpan" name="btnSimpan">
   </td>
  </tr>
 </table>
</form>
<?php
 if (isset($_POST["btnSimpan"]))
 {
  #tampung ke variabel yang isian dari form
  $kode = $_POST["txtKd"];
  $nama = $_POST["txtNm"];
  $harga = $_POST["txtHr"];
  
  #coba cek ada gak isinya
  echo $kode . $nama . $harga;
  $query = $koneksi->query("INSERT INTO `db_kk0918`.`barang` (`KdBrg`, `NmBrg`, `Harga`) VALUES ('$kode', '$nama', '$harga')");

 } #akhir tombol simpan diklik
?>

Buka web pada menu "index.php" dan "entry.php" untuk menjalankannya.

file baru css dengan nama "style1.css" dan isi script

.tombol {
    border-color: red;
   color: white; 
   padding: 5px 10px;
   background: #000000;
   display: table;
}
.tombol1 {
   color: white; 
   padding: 5px 10px;
   background: #a3a375;
   margin: 5px;
   display: block;
   /*hilangkan garis bawah pada teks*/
        text-decoration: none;
   /*teks rata tengah*/
        text-align: center;     
}
.tombol1:hover{
  background: #0f0f0a;
}

Edit Script "index.php"

<?php
  error_reporting(~E_NOTICE); #ini digunakan utk menyembunyikan error khusus notice khususnya di index / beranda
 $koneksi = new mysqli("localhost", "root", "", "db_kk0918");
 if ($koneksi->connect_error) 
 {
  echo "Gagal terhubung karena " . $koneksi->connect_error;
 }
?>
<link rel="stylesheet" type="text/css" href="style1.css">
<table border="1" width="80%" align="center">
 <tr align="center">
  <td colspan="2"><img src="images/header.png" height="64px" width="100%"></td>
 </tr>
 <tr>
  <td width="10%">
   <h3>Menu</h3>
   <!-- <ul id="simple">
       <li><a href="index.php">Beranda</a></li>
       <li><a href="index.php?hal=tentang.php">Tentang</a></li>
       <li><a href="index.php?hal=entry.php">Entry (C)</a></li>
       <li><a href="index.php?hal=tampil.php">Tampil (R)</a></li>
       <li><a href="index.php?hal=ubah.php">Ubah (U)</a></li>
       <li><a href="index.php?hal=hapus.php">Hapus (D)</a></li>
   </ul> -->

   <a href="index.php" class="tombol1">Beranda</a>
   <a href="index.php?hal=tentang.php" class="tombol1">Tentang</a>
   <a href="index.php?hal=entry.php" class="tombol1">Entry (C)</a>
   <a href="index.php?hal=tampil.php" class="tombol1">Tampil (R)</a>
   <a href="index.php?hal=ubah.php" class="tombol1">Ubah (U)</a>
   <a href="index.php?hal=hapus.php" class="tombol1">Hapus (D)</a>

  </td>
  <td align="justify">
   <?php 
    $hal = $_GET["hal"]; #echo $_GET["hal"]; utk nampilin isi yang dari kita get/post dari index.php?hal=xxx.php
    if (isset($hal) && $hal!="")
    { #kondisi ini akan dijalankan jika variabel $hal digunakan dan variabel $hal  isinya bukan kosong
     include($hal); 
    }
    else
    {
     echo "<h1>Selamat Datang</h1><p>Saya datang dari Habang, jauh menuntut ilmu, biarlah yang penting saya bisa. Saya yakin pasti bisa <strong>#nekbisanekkawa</strong></p>";
    }
   ?>
  </td>
 </tr>
 <tr align="center">
  <td colspan="2" background="images/akbar.png">footer</td>
 </tr>
</table>

Edit Script "entry.php"

<link rel="stylesheet" type="text/css" href="style1.css">
<form method="POST">
  <h1>Entry Data Barang</h1>
 <table>
  <tr>
   <td>Kode Barang :</td>
   <td><input type="text" name="txtKd"></td>
  </tr>
  <tr>
   <td>Nama Barang :</td>
   <td><input type="text" name="txtNm"></td>
  </tr>
  <tr>
   <td>Harga :</td>
   <td><input type="text" name="txtHr" onkeyup="this.value=this.value.replace(/[^\d]/,'')"></td>
  </tr>
  <tr>
   <td colspan="2">
    <input class="tombol" type="submit" value="Simpan" name="btnSimpan">
   </td>
  </tr>
 </table>
</form>
<?php
 if (isset($_POST["btnSimpan"]))
 {
  #tampung ke variabel yang isian dari form
  $kode = $_POST["txtKd"];
  $nama = $_POST["txtNm"];
  $harga = $_POST["txtHr"];
  
  #coba cek ada gak isinya
  echo $kode . $nama . $harga;
  $query = $koneksi->query("INSERT INTO `db_kk0918`.`barang` (`KdBrg`, `NmBrg`, `Harga`) VALUES ('$kode', '$nama', '$harga')");

 } #akhir tombol simpan diklik
?>

Buka web pada menu "index.php" dan "entry.php" untuk menjalankannya.