UTS - PWEB - Membuat Input Prestasi Siswa dengan MySQL

UTS - Pemrograman Web
Membuat Input Prestasi Siswa dan kemudian dimasukkan kedalam database MySQL dengan menggunakan php
Nama : Bastian Farandy
NRP : 05111740000190
Kelas : Pemrograman Web C
Source Code :

config.php

 <?php  
 $server = "localhost";  
 $user = "root";  
 $password = "";  
 $nama_database = "pendaftaran_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>Input Prestasi Siswa | E-Rapor</title>  
   <style type="text/css">  
     ul{  
        display:table; margin:0 auto;  
     }  
     body {  
       background-color: #80deea;    
     }  
     fieldset{  
       background-color: #b4ffff;  
     }  
   </style>  
 </head>  
 <body>  
   <header>  
     <h3 align="center">Input Prestasi Siswa</h3>  
     <h1 align="center">E-Rapor</h1>  
   </header>  
   <fieldset>  
   <h4 align="center">Menu</h4>  
   <nav>  
     <ul>  
       <li><a href="form-daftar.php"><button type="button">Input Prestasi Siswa</button></a></li><br/>  
       <li><a href="list-siswa.php"><button type="button">List Siswa</button></a></li>  
     </ul>  
   </nav>  
   <?php if(isset($_GET['status'])): ?>  
   <p align="center">  
     <?php  
       if($_GET['status'] == 'sukses'){  
         echo "Input Prestasi Siswa telah berhasil!";  
       } else {  
         echo "Pendaftaran gagal!";  
       }  
     ?>  
   </p>  
   <?php endif; ?>  
   </fieldset>  
   </body>  
 </html>  

form-daftar.php

 <!DOCTYPE html>  
 <html>  
 <head>  
   <title>Input Prestasi Siswa | Sekolah Koding</title>  
   <style type="text/css">  
     ul{  
        display:table; margin:0 auto;  
     }  
     body {  
       background-color: #80deea;    
     }  
     fieldset{  
       background-color: #b4ffff;  
     }  
   </style>  
 </head>  
 <body>  
   <header>  
     <h3 align="center">Formulir Penginputan Prestasi Siswa | E-Rapor</h3>  
   </header>  
   <form action="proses-pendaftaran.php" method="POST">  
     <fieldset>  
     <ul>  
       <li>  
       <label for="nama">Nama Siswa&emsp;: </label>  
       <input type="text" name="nama" placeholder="nama lengkap" />  
     </li>  
       <br/>  
     <li>  
       <label for="jenis_prestasi">Jenis Prestasi: </label>  
       <textarea name="jenis_prestasi"></textarea>  
     </li>  
     <br/>  
     <li>  
       <label for="Kelas">Kelas&emsp;&emsp;&emsp;: </label>  
       <input type="text" name="Kelas" placeholder="Kelas" />  
     </li>  
     <br/>  
     <li>  
       <label for="sekolah">Sekolah&emsp;&emsp;: </label>  
       <input type="text" name="sekolah" placeholder="Kelas" />  
     </li>  
     <br/>  
     <li>  
       <label for="Keterangan">Keterangan&emsp;: </label>  
       <textarea name="Keterangan"></textarea>  
     </li>  
     <p align="center">  
       <input type="submit" value="Daftar" name="daftar" />  
       &emsp;<a href="index.php"><button type="button">Menu Utama</button></a>  
     </p>  
     </fieldset>  
   </form>  
   </body>  
 </html>  

hapus.php

 <?php  
 include("config.php");  
 if( isset($_GET['id']) ){  
   // ambil id dari query string  
   $id = $_GET['id'];  
   // buat query hapus  
   $sql = "DELETE FROM prestasi_siswa 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...");  
 }  
 ?>  

proses-pendaftaran.php

 <?php  
 include("config.php");  
 // cek apakah tombol daftar sudah diklik atau blum?  
 if(isset($_POST['daftar'])){  
   // ambil data dari formulir  
   $nama = $_POST['nama'];  
   $jenis_prestasi = $_POST['jenis_prestasi'];  
   $sekolah = $_POST['sekolah'];  
   $Kelas = $_POST['Kelas'];  
   $Keterangan = $_POST['Keterangan'];  
   // buat query  
   $sql = "INSERT INTO prestasi_siswa (Nama_Siswa, Jenis_Prestasi, Kelas, sekolah, Keterangan) VALUE ('$nama', '$jenis_prestasi', '$Kelas', '$sekolah', '$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>Input Prestasi Siswa | E-Rapor</title>  
   <style type="text/css">  
     th, td {  
        padding: 15px;  
        text-align: left;  
       }  
     body {  
       background-color: #80deea;    
     }  
     fieldset{  
       background-color: #b4ffff;  
     }  
     table{  
       background-color: white;   
     }  
   </style>  
 </head>  
 <body>  
   <header>  
     <h3 align="center">Siswa berprestasi yang telah di Input | E-Rapor</h3>  
   </header>  
   <fieldset>  
   <nav>  
     <p align="center"><a href="form-daftar.php"><button type="button">Tambah Baru</button></a></p>  
   </nav>  
   <br>  
   <table border="1" align="center">  
   <thead>  
     <tr>  
       <th>No</th>  
       <th>ID</th>  
       <th>Nama Siswa</th>  
       <th>Jenis Prestasi</th>  
       <th>Kelas</th>  
       <th>Sekolah</th>  
       <th>Keterangan</th>  
       <th>Opsi</th>  
     </tr>  
   </thead>  
   <tbody>  
     <?php  
     $sql = "SELECT * FROM prestasi_siswa";  
     $query = mysqli_query($db, $sql);  
     $nomor = 0;  
     while($siswa = mysqli_fetch_array($query)){  
       echo "<tr>";  
       $nomor++;  
       echo "<td>".$nomor."</td>";  
       echo "<td>".$siswa['id']."</td>";  
       echo "<td>".$siswa['Nama_Siswa']."</td>";  
       echo "<td>".$siswa['Jenis_Prestasi']."</td>";  
       echo "<td>".$siswa['Kelas']."</td>";  
       echo "<td>".$siswa['sekolah']."</td>";  
       echo "<td>".$siswa['Keterangan']."</td>";  
       echo "<td>";  
       echo "<a href='hapus.php?id=".$siswa['id']."'>Hapus</a>";  
       echo "</td>";  
       echo "</tr>";  
     }  
     ?>  
   </tbody>  
   </table>  
   <p align="center">Total Siswa : <?php echo mysqli_num_rows($query) ?><br/><br/>  
   <a href="index.php"><button type="button">Menu Utama</button></a></p></fieldset>  
   </body>  
 </html>  

Screenshot


Keterangan : Tampilan Utama dari Input Prestasi E-Rapor


Keterangan : Tampilan dari Formulir Penginputan Prestasi Siswa


Keterangan : Setelah input, maka akan ada pesan bahwa Input Prestasi Siswa telah berhasil


Keterangan : Tampilan dari list siswa yang telah diinput


Keterangan : Setelah user menginput data siswa selanjutnya, maka pada list siswa yang telah terdaftar akan di update (ditambah)


Keterangan : Setelah user menekan opsi 'Hapus' pada ID 9 dengan siswa bernama Bastian Farandy, maka dalam list siswa yang sudah terdaftar akan diupdate dan ID 9 akan di delete.

Keterangan : Tampilan Utama pada Database

Catatan :
  • Pada web yang saya buat, berbeda dengan yang saya tuliskan di kertas ujian karena ada beberapa fitur dan keterangan yang saya tambahkan setelah kertas ujian sudah dikumpulkan. 

Comments

Popular posts from this blog

PWEB5 - Membuat Form Pembayaran Air

MPPL1 - Mendeskripsikan Proyek

PBO1 - Biodata dengan BlueJ