Tuesday, October 16, 2018

UTS PWeb C - Membuat E-Rapor Prestasi Siswa

Nama : Haikal Almaz Said
NRP : 05111740000068
Kelas : Pemrograman Web C


Pada postingan kali ini saya akan membagikan hasil UTS PWeb saya yaitu membuat E-Rapor untuk Prestasi Siswa, berikut Source Code dan Screenshot tampilan dari E-Rapor tersebut :


1. Source Code
  • config.php

 <?php  
 $server = "localhost";  
 $user = "root";  
 $password = "";  
 $nama_database = "prestasi_siswa";  
 $db = mysqli_connect($server, $user, $password, $nama_database);  
 if( !$db ){  
   die("Gagal terhubung dengan database: " . mysqli_connect_error());  
 }  
 ?>  

  • index.php

<!DOCTYPE html>
<html>
<head>
    <title>E-Rapor SMA Luar Biasa</title>
 <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
    <header>
        <h3>E-Rapor Prestasi Siswa SMA Luar Biasa</h3>
    </header>

    <h4>Menu</h4>
    <nav>
        <ul>
            <a href="form-daftar.php">Tambah Prestasi</a><br>
            <a href="list-siswa.php">List Prestasi</a>
        </ul>
    </nav>
 <?php if(isset($_GET['status'])): ?>
  <p>
        <?php
            if($_GET['status'] == 'sukses'){
                echo "Pendaftaran siswa baru berhasil!";
            } else {
                echo "Pendaftaran gagal!";
            }
        ?>
  </p>
  <?php endif; ?>
    </body>
</html>

  • form-daftar.php

<!DOCTYPE html>
<html>
<head>
    <title>Formulir Prestasi Siswa</title>
 <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
    <header>
        <h3>Formulir Pendaftaran Prestasi Siswa</h3>
    </header>

    <form action="proses-pendaftaran.php" method="POST">

        <fieldset>
  <p>
            <label for="kelas">Kelas: </label>
            <select name="kelas">
                <option>X IPA 1</option>
                <option>X IPA 2</option>
    <option>X IPS 1</option>
    <option>XI IPA 1</option>
                <option>XI IPA 2</option>
    <option>XI IPS 1</option>
    <option>XII IPA 1</option>
                <option>XII IPA 2</option>
    <option>XII IPS 1</option>
            </select>
        </p>
  <p>
            <label for="semester">Semester: </label>
            <select name="semester">
                <option>1</option>
                <option>2</option>
            </select>
        </p>
        <p>
            <label for="nama">Nama: </label>
            <input type="text" name="nama" placeholder="Nama Lengkap" />
        </p>
  <p>
            <label for="nis">NIS: </label>
            <input type="text" name="nis" placeholder="Masukkan NIS" />
        </p>
  <p>
            <label for="jenis_prestasi">Jenis Prestasi: </label>
            <select name="jenis_prestasi">
                <option>Akademik</option>
                <option>Kurikuler</option>
                <option>Lainnya</option>
            </select>
        </p>
        <p>
            <label for="keterangan">Keterangan: </label>
            <textarea name="keterangan" placeholder="Masukkan keterangan prestasi siswa"></textarea>
        </p>
        <p>
   <button type="cancel" onclick="window.location='index.php';return false;">Batal</button>
   <input type="submit" value="Simpan" name="daftar" />
  </p>

        </fieldset>

    </form>

    </body>
</html>

  • proses-pendaftaran.php

 <?php  
 include("config.php");  
 if(isset($_POST['daftar'])){  
   // ambil data dari formulir  
      $kelas = $_POST['kelas'];  
      $semester = $_POST['semester'];  
   $nama = $_POST['nama'];  
   $nis = $_POST['nis'];  
   $jenis_prestasi = $_POST['jenis_prestasi'];  
   $keterangan = $_POST['keterangan'];  
   // buat query  
   $sql = "INSERT INTO data_prestasi (kelas, semester, nama, nis, jenis_prestasi, keterangan) VALUE ('$kelas', '$semester', '$nama', '$nis', '$jenis_prestasi', '$keterangan')";  
   $query = mysqli_query($db, $sql);  
   // apakah query simpan berhasil?  
   if( $query ) {  
     // kalau berhasil alihkan ke halaman index.php dengan status=sukses  
     header('Location: index.php?status=sukses');  
   } else {  
     // kalau gagal alihkan ke halaman indek.php dengan status=gagal  
     header('Location: index.php?status=gagal');  
   }  
 } else {  
   die("Akses dilarang...");  
 }  
 ?>  
  • list-siswa.php

<?php include("config.php"); ?>

<!DOCTYPE html>
<html>
<head>
    <title>Daftar Prestasi</title>
 <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
    <header>
        <h3>Daftar Prestasi Siswa SMA Luar Biasa</h3>
    </header>

    <nav>
        <a href="form-daftar.php">[+] Tambah Baru</a>
    </nav>

    <br>

    <table border="1" align="center">
    <thead>
        <tr>
            <th>No</th>
            <th>Kelas</th>
            <th>Semester</th>
            <th>Nama</th>
            <th>NIS</th>
            <th>Jenis Prestasi</th>
            <th>Keterangan</th>
   <th>Aksi</th>
        </tr>
    </thead>
    <tbody>

        <?php
        $sql = "SELECT * FROM data_prestasi";
        $query = mysqli_query($db, $sql);

        while($siswa = mysqli_fetch_array($query)){
            echo "<tr>";

            echo "<td>".$siswa['id']."</td>";
            echo "<td>".$siswa['kelas']."</td>";
            echo "<td>".$siswa['semester']."</td>";
            echo "<td>".$siswa['nama']."</td>";
            echo "<td>".$siswa['nis']."</td>";
            echo "<td>".$siswa['jenis_prestasi']."</td>";
   echo "<td>".$siswa['keterangan']."</td>";

            echo "<td>";
            echo "<a href='form-edit.php?id=".$siswa['id']."'>Edit</a> | ";
            echo "<a href='hapus.php?id=".$siswa['id']."'>Hapus</a>";
            echo "</td>";

            echo "</tr>";
        }
        ?>

    </tbody>
    </table>

    <p align="center">Total: <?php echo mysqli_num_rows($query) ?></p>
 <p align="center"><button type="cancel" onclick="window.location='index.php';return false;">Kembali</button></p>

    </body>
</html>

  • form-edit.php

 <?php

include("config.php");

// kalau tidak ada id di query string
if( !isset($_GET['id']) ){
    header('Location: list-siswa.php');
}

//ambil id dari query string
$id = $_GET['id'];

// buat query untuk ambil data dari database
$sql = "SELECT * FROM data_prestasi WHERE id=$id";
$query = mysqli_query($db, $sql);
$siswa = mysqli_fetch_assoc($query);

// jika data yang di-edit tidak ditemukan
if( mysqli_num_rows($query) < 1 ){
    die("data tidak ditemukan...");
}

?>

<!DOCTYPE html>
<html>
<head>
    <title>Edit Prestasi Siswa</title>
 <link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
    <header>
        <h3>Formulir Edit Prestasi Siswa</h3>
    </header>

    <form action="proses-edit.php" method="POST">

        <fieldset>

            <input type="hidden" name="id" value="<?php echo $siswa['id'] ?>" />
  
  <p>
            <label for="kelas">Kelas: </label>
            <?php $kelas = $siswa['kelas']; ?>
            <select name="kelas">
                <option <?php echo ($kelas == 'X IPA 1') ? "selected": "" ?>>X IPA 1</option>
                <option <?php echo ($kelas == 'X IPA 2') ? "selected": "" ?>>X IPA 2</option>
                <option <?php echo ($kelas == 'X IPS 1') ? "selected": "" ?>>X IPS 1</option>
                <option <?php echo ($kelas == 'XI IPA 1') ? "selected": "" ?>>XI IPA 1</option>
                <option <?php echo ($kelas == 'XI IPA 2') ? "selected": "" ?>>XI IPA 2</option>
                <option <?php echo ($kelas == 'XI IPS 1') ? "selected": "" ?>>XI IPS 1</option>
    <option <?php echo ($kelas == 'XII IPA 1') ? "selected": "" ?>>XII IPA 1</option>
                <option <?php echo ($kelas == 'XII IPA 2') ? "selected": "" ?>>XII IPA 2</option>
                <option <?php echo ($kelas == 'XII IPS 1') ? "selected": "" ?>>XII IPS 1</option>
            </select>
        </p>
  <p>
            <label for="semester">Semester: </label>
            <?php $semester = $siswa['semester']; ?>
            <select name="semester">
                <option <?php echo ($semester == '1') ? "selected": "" ?>>1</option>
                <option <?php echo ($semester == '2') ? "selected": "" ?>>2</option>
            </select>
        </p>
        <p>
            <label for="nama">Nama: </label>
            <input type="text" name="nama" placeholder="Nama Lengkap" value="<?php echo $siswa['nama'] ?>" />
        </p>
  <p>
            <label for="nis">NIS: </label>
            <input type="text" name="nis" placeholder="Masukkan NIS" value="<?php echo $siswa['nama'] ?>" />
        </p>
  <p>
            <label for="jenis_prestasi">Jenis Prestasi: </label>
            <?php $jenis_prestasi = $siswa['jenis_prestasi']; ?>
            <select name="jenis_prestasi">
                <option <?php echo ($jenis_prestasi == 'Akademik') ? "selected": "" ?>>Akademik</option>
                <option <?php echo ($jenis_prestasi == 'Kurikuler') ? "selected": "" ?>>Kurikuler</option>
    <option <?php echo ($jenis_prestasi == 'Lainnya') ? "selected": "" ?>>Lainnya</option>
   </select>
        </p>
  <p>
            <label for="keterangan">Keterangan: </label>
            <textarea name="keterangan" placeholder="Masukkan keterangan prestasi"><?php echo $siswa['keterangan'] ?></textarea>
        </p>
        <p>
   <button type="cancel" onclick="window.location='list-siswa.php';return false;">Batal</button>
            <input type="submit" value="Simpan" name="simpan" />
        </p>

        </fieldset>


    </form>

    </body>
</html>

  • proses-edit.php

 <?php  
 include("config.php");  
 // cek apakah tombol simpan sudah diklik atau blum?  
 if(isset($_POST['simpan'])){  
   // ambil data dari formulir  
   $id = $_POST['id'];  
   $kelas = $_POST['kelas'];  
      $semester = $_POST['semester'];  
   $nama = $_POST['nama'];  
   $nis = $_POST['nis'];  
   $jenis_prestasi = $_POST['jenis_prestasi'];  
   $keterangan = $_POST['keterangan'];  
   // buat query update  
   $sql = "UPDATE data_prestasi SET kelas='$kelas', semester='$semester', nama='$nama', nis='$nis', jenis_prestasi='$jenis_prestasi', keterangan='$keterangan' WHERE id=$id";  
   $query = mysqli_query($db, $sql);  
   // apakah query update berhasil?  
   if( $query ) {  
     // kalau berhasil alihkan ke halaman list-siswa.php  
     header('Location: list-siswa.php');  
   } else {  
     // kalau gagal tampilkan pesan  
     die("Gagal menyimpan perubahan...");  
   }  
 } else {  
   die("Akses dilarang...");  
 }  
 ?>  

  • hapus.php

 <?php  
 include("config.php");  
 if( isset($_GET['id']) ){  
   // ambil id dari query string  
   $id = $_GET['id'];  
   // buat query hapus  
   $sql = "DELETE FROM data_prestasi WHERE id=$id";  
   $query = mysqli_query($db, $sql);  
   // apakah query hapus berhasil?  
   if( $query ){  
     header('Location: list-siswa.php');  
   } else {  
     die("gagal menghapus...");  
   }  
 } else {  
   die("akses dilarang...");  
 }  
 ?>  

  • style.css

 body {  
      background-color : Aquamarine;  
 }  
 h4 {  
      font-family : calibri;  
      text-align : center;  
 }  
 nav {  
      font-family : calibri;  
      text-align : center;  
 }  
 header {  
      width: 90%;  
      margin: auto;  
      height: 120px;  
      line-height: 120px;  
      background: #4169E1;  
      color: #FFFFFF;  
      font-family: calibri;  
      text-align : center;  
 }  
 p {  
      font-family : calibri;  
 }  


2. Screenshot Tampilan





sekian postingan saya kali ini terima kasih.

No comments:

Post a Comment