UTS PWEB C

Nama : Moh. Iman Afandy
Kelas : Pweb C
NRP : 0511140000129

Berikut jawaban saya untuk soal UTS Pweb no.3,





















source code :

style.css


@font-face  
 {  
      font-family: caviar;  
      src: url(CaviarDreams.ttf);  
 }  
 body   
 {   
    background: #adad85;   
    color: #333;   
    width: 100%;   
    font-family: sans-serif;   
    margin: 0 auto;   
  }   
 .content  
 {  
    margin: 2em auto;  
    width: 80%;  
    background: #4e5868;  
    border-radius: 3px;  
 }  
 .form  
 {  
    padding: 1em;  
    margin: 2em auto;  
    width: 80%;  
    background: #fff;  
    border-radius: 3px;  
 }  
 label {  
   padding: 12px 12px 12px 0;  
   display: inline-block;  
 }  
 .container   
 {  
   border-radius: 5px;  
   padding: 20px;  
 }  
 .col-25   
 {  
   float: left;  
   width: 25%;  
   margin-top: 6px;  
 }  
 .col-75 {  
   float: left;  
   width: 75%;  
   margin-top: 6px;  
 }  
 .row:after {  
   content: "";  
   display: table;  
   clear: both;  
 }  
 input[type="text"],  
 input[type="email"],  
 input[type="date"],  
 textarea   
 {  
    border: 1px solid #ccc;  
    padding: 12px;  
    width: 100%;  
    background: #efefef;  
    font-size: 10pt;  
    margin: 6px 0px;  
    border-radius: 4px;  
 }  
 input[type=submit] {  
   background-color: #4286f4;  
   color: white;  
   padding: 12px 20px;  
   border: none;  
   border-radius: 4px;  
   cursor: pointer;  
   float: right;  
 }  
 input[type=submit]:hover {  
   background-color: #1058cc;  
 }  
 .header  
 {   
    margin-left: 0;   
    background: #fff;   
 }   
 .menu  
 {   
    background-color: #adad85;   
    height: 50px;   
    line-height: 50px;   
 }  
  .menu1  
  {   
    background-color: #adad85;   
    height: 60px;   
    line-height: 60px;    
    margin: 0;    
  }   
  .menu ul  
  {   
    list-style: none;   
  }   
  .menu ul li a  
  {   
    float: left;   
    width: 10%;   
    display: block;   
    text-align: center;   
    color: #A4A4A4;   
    text-decoration: none;   
  }   
  .menu ul li a:hover  
  {   
    color: #000000;  
    display:block;   
  }   
  .menu1 ul  
  {   
    list-style: none;   
    border-bottom: solid #f3f3f3 0.6px;  
  }   
  .menu1 ul li a  
  {   
    float: left;   
    width: 10%;   
    display: block;   
    text-align: center;   
    color: #A4A4A4;   
    text-decoration: none;   
  }   
  .menu1 ul li a:hover  
  {   
    color: #000000;   
    display:block;   
  }   
  .content  
  {   
    width: 88%;   
    margin: auto;    
    padding: 0.1px;   
    background: #fff;   
    color: #333;   
  }   
  .kiri  
  {   
    width: 70%;   
    float: left;   
    margin: auto;   
    background: #fff;    
  }   
  .kanan  
  {   
    width: 25%;   
    float: left;   
    margin: auto;   
    background: #fff;    
  }   
 .kanan p  
 {   
    font-size: 12px;   
    margin: 0;   
    text-align:center;   
    margin: 10px;    
    color:#D9D8D8;   
  }   
  .border  
  {    
    height: 200px;   
    margin-top: 1pc;   
    padding-bottom: 3pc;   
    padding-right: 2pc;   
  }   
  .undecor  
  {   
    text-decoration: none;   
  }   
  .jarak  
  {   
    padding: 0.2pc;  
  }  
  .footer  
  {    
    margin: auto;   
    height: 40px;   
    line-height: 40px;   
    background: #F0EEEE;   
  }  
  h3{   
    font-family: "Lucida Console";   
    font-weight: bold;   
    font-size: 24px;   
  }   
  p{   
    font-family: "Verdana";   
    font-size: 14px;   
    font-weight: lighter;   
    color: #ADACAC;   
  }   
  h1{   
    font-family: "Verdana";   
    font-size: 13px;   
    font-weight: bold;   
    text-align: center;   
    padding-top: 10px;   
  }   
  h2{   
    font-family: "Lucida Console";   
    font-weight: lighter;   
    font-size: 12px;   
  }    
 #errorname{  
    display: none;  
 }  
 #erroraddress{  
    display: none;  
 }  
  #erroremail {  
    display: none;  
  }  
  #errornumber{  
    display: none;  
  }  
  #errorbirthdate{  
    display: none;  
  }  


hapus.php
}
 <?php  
 include("config.php");  
 if(isset($_GET['id'])){  
      // ambil id dari query string  
      $id = $_GET['id'];  
      //buat query hapus  
      $sql = "DELETE FROM calon_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-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'];  
   $nama = $_POST['nama'];  
   $alamat = $_POST['alamat'];  
   $jk = $_POST['jenis_kelamin'];  
   $kelas = $_POST['kelas'];  
   $semester = $_POST['semester'];  
   $prestasi = $_POST['prestasi'];  
   $keterangan = $_POST['keterangan'];  
   // buat query update  
   $sql = "UPDATE calon_siswa SET nama='$nama', alamat='$alamat', jenis_kelamin='$jk', kelas='$kelas', semester='$semester', prestasi='$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...");  
 }  
 ?>  


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 calon_siswa 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>Formulir Edit Siswa Berprestasi | SMA AL-AZHAR PALU</title>  
      <style type="text/css" href="style.css">  
           body{  
                background-color: #a1fc23  
           }  
           input[type=text], select {  
             width: 50%;  
             padding: 12px 20px;  
             margin: 8px 0;  
             display: inline-block;  
             border: 1px solid #ccc;  
             border-radius: 4px;  
             box-sizing: border-box;  
           }  
           input[type=submit] {  
             width: 10%;  
             background-color: #4CAF50;  
             color: white;  
             padding: 14px 20px;  
             margin: 8px 0;  
             border: none;  
             border-radius: 4px;  
             cursor: pointer;  
           }  
           textarea {  
                  width: 50%;  
             height: 50px;  
             padding: 12px 20px;  
             box-sizing: border-box;  
             border: 2px solid #ccc;  
             border-radius: 4px;  
             background-color: #f8f8f8;  
             resize: none;  
           }  
      </style>  
 </head>  
 <body>  
      <header><center>  
           <h3>Formulir Edit Siswa Berprestasi | SMA AL-AZHAR PALU</h3>  
      </center></header>  
      <center>  
      <form action="proses-edit.php" method="POST">  
           <fieldset>  
                <input type="hidden" name="id" value="<?php echo $siswa['id'] ?>" />  
           <p>  
                <label for="nama">Nama: </label>  
                <input type="text" name="nama" placeholder="nama lengkap" value="<?php echo $siswa['nama'] ?>" />  
           </p>  
           <p>  
                <label for="alamat">Alamat: </label>  
       <textarea name="alamat"><?php echo $siswa['alamat'] ?></textarea>  
           </p>  
           <p>  
                <label for="jenis_kelamin">Jenis Kelamin: </label>  
       <?php $jk = $siswa['jenis_kelamin']; ?>  
       <label><input type="radio" name="jenis_kelamin" value="laki-laki" <?php echo ($jk == 'laki-laki') ? "checked": "" ?>> Laki-laki</label>  
       <label><input type="radio" name="jenis_kelamin" value="perempuan" <?php echo ($jk == 'perempuan') ? "checked": "" ?>> Perempuan</label>  
           </p>  
           <p>  
                <label for="kelas">Kelas: </label>  
                <input type="text" name="kelas" placeholder="kelas" value="<?php echo $siswa['kelas'] ?>" />  
           </p>  
           <p>  
                <label for="semester">Semester: </label>  
                <input type="text" name="semester" placeholder="semester" value="<?php echo $siswa['semester'] ?>" />  
           </p>  
           <p>  
       <label for="prestasi">Prestasi: </label>  
       <?php $prestasi = $siswa['prestasi']; ?>  
       <select name="prestasi">  
         <option <?php echo ($prestasi == 'Kurikuler') ? "selected": "" ?>>Kurikuler</option>  
         <option <?php echo ($prestasi == 'Akademik') ? "selected": "" ?>>Akademik</option>  
       </select>  
     </p>  
     <p>  
       <label for="keterangan">Keterangan: </label>  
       <textarea name="keterangan"><?php echo $siswa['keterangan'] ?></textarea>  
     </p>  
     <p>  
       <input type="submit" value="Simpan" name="simpan" />  
     </p>  
           </fieldset>  
      </form>  
      </center>  
 </body>  
 </html>  
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'];  
   $alamat = $_POST['alamat'];  
   $jk = $_POST['jenis_kelamin'];  
   $kelas = $_POST['kelas'];  
   $semester = $_POST['semester'];  
   $prestasi = $_POST['prestasi'];  
   $keterangan = $_POST['keterangan'];  
   // buat query  
   $sql = "INSERT INTO calon_siswa (nama, alamat, jenis_kelamin, kelas, semester, prestasi, keterangan) VALUE ('$nama', '$alamat', '$jk', '$kelas', '$semester', '$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...");  
 }  
 ?>  
form-daftar.php
 <!DOCTYPE html>  
 <html>  
 <head>  
      <title>Pendaftaran Data Prestasi SMA AL-AZHAR PALU</title>  
      <style type="text/css" href="style.css">  
           body{  
                background-color: #a1fc23  
           }  
           input[type=text], select {  
             width: 50%;  
             padding: 12px 20px;  
             margin: 8px 0;  
             display: inline-block;  
             border: 1px solid #ccc;  
             border-radius: 4px;  
             box-sizing: border-box;  
           }  
           input[type=submit] {  
             width: 10%;  
             background-color: #4CAF50;  
             color: white;  
             padding: 14px 20px;  
             margin: 8px 0;  
             border: none;  
             border-radius: 4px;  
             cursor: pointer;  
           }  
           textarea {  
                  width: 50%;  
             height: 50px;  
             padding: 12px 20px;  
             box-sizing: border-box;  
             border: 2px solid #ccc;  
             border-radius: 4px;  
             background-color: #f8f8f8;  
             resize: none;  
           }  
           @font-face{  
                font-family: caviar;  
                src: url(CaviarDreams.ttf);  
           }  
      </style>  
 </head>  
 <body>  
      <font style="font-family: caviar">  
      <header>  
           <h3><center>Formulir Pendaftaran Prestasi Siswa</center></h3>  
      </header>  
      <form action="proses-pendaftaran.php" method="POST">  
           <fieldset>  
           <p>  
                <div class="col-25">  
                     <label for="nama">Nama:</label>  
                </div>  
                <div class="col-75">  
                     <input type="text" name="nama" placeholder="nama lengkap">  
                </div>  
           </p>  
           <p>  
                <div class="col-25">  
                     <label for="alamat">Alamat:</label>  
                </div>  
                <div class="col-75">  
                     <textarea name="alamat"></textarea>  
                </div>  
           </p>  
           <p>  
                <div class="col-25">  
       <label for="jenis_kelamin">Jenis Kelamin: </label>  
          </div>  
          <div class="col-75">  
       <label><input type="radio" name="jenis_kelamin" value="laki-laki"> Laki-laki</label><br>  
       <label><input type="radio" name="jenis_kelamin" value="perempuan"> Perempuan</label>  
          </div>  
     </p>  
           <p>  
                <div class="col-25">  
                     <label for="kelas">Kelas:</label>  
                </div>  
                <div class="col-75">  
                <input type="text" name="kelas" placeholder="kelas">  
                <div class="col-75">  
           </p>  
           <p>  
                <div class="col-25">  
                <label for="semester">Semester:</label>  
                </div>  
                <div class="col-75">  
                <input type="text" name="semester" placeholder="semester">  
                </div>  
           </p>  
           <p>  
                <div class="col-25">  
                     <label for="prestasi">Prestasi:</label>  
                </div>  
                <div class="col-75">  
                     <select name="prestasi">  
                          <option value="kurikuler">Kurikuler</option>  
                          <option value="akademik">Akademik</option>  
                     </select>  
                </div>  
           </p>  
           <p>  
                <div class="col-25">  
                <label for="keterangan">Keterangan:</label>  
                </div>  
                <div class="col-75">  
                <textarea name="keterangan"></textarea>  
                </div>  
           </p>  
           <p>  
                <input type="submit" value="Daftar" name="daftar"/>  
           </p>  
           </fieldset>  
      </form>  
      </font>  
 </body>  
 </html>  
list-siswa.php
<?php include("config.php"); ?>  
 <!DOCTYPE html>  
 <html>  
 <head>  
      <title>Pendaftaran Data Prestasi SMA AL-AZHAR PALU</title>  
      <style type="text/css" href="style.css">  
           body{  
                background-color: #a1fc23  
           }  
           @font-face{  
                font-family: caviar;  
                src: url(CaviarDreams.ttf);  
           }  
      </style>  
 </head>  
 <body>  
      <font style="font-family: caviar">  
      <header>  
           <h3><center>Daftar Siswa Berprestasi</center></h3>  
      </header>  
      <nav>  
           <a href="form-daftar.php">[+] Tambah Baru</a>  
      </nav>  
      <br>  
      <table border="1">  
           <thead>  
                <tr>  
                     <th>No</th>  
                     <th>Nama</th>  
                     <th>Alamat</th>  
                     <th>Jenis Kelamin</th>  
                     <th>Kelas</th>  
                     <th>Semester</th>  
                     <th>Prestasi</th>  
                     <th>Keterangan</th>  
                     <th>Tindakan</th>  
                </tr>  
           </thead>  
           <tbody>  
                <?php  
                $sql = "SELECT * FROM calon_siswa";  
                $query = mysqli_query($db,$sql);  
                while($siswa = mysqli_fetch_array($query)){  
                     echo "<tr>";  
                     echo "<td>".$siswa['id']."</td>";  
                     echo "<td>".$siswa['nama']."</td>";  
                     echo "<td>".$siswa['alamat']."</td>";  
                     echo "<td>".$siswa['jenis_kelamin']."</td>";  
                     echo "<td>".$siswa['kelas']."</td>";  
                     echo "<td>".$siswa['semester']."</td>";  
                     echo "<td>".$siswa['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>Total : <?php echo mysqli_num_rows($query) ?></p>       
      </font>  
 </body>  
 </html>  
index.php
<!DOCTYPE html>  
 <html>  
 <head>  
      <title>Pendaftaran Data Prestasi SMA AL-AZHAR PALU</title>  
      <style type="text/css" href="style.css">  
           body{  
                background-color: #a1fc23  
           }  
           @font-face{  
                font-family: caviar;  
                src: url(CaviarDreams.ttf);  
           }  
      </style>  
 </head>  
 <body>  
      <header><font style="font-family: caviar;">  
      <h3><center>Pendaftaran Data Siswa Berpestasi</center></h3>  
      <h1><center>SMA AL-AZHAR PALU<center></center></h1>  
      </center></font></header>  
      <center>  
      <h4><Menu</h4>  
      <nav>  
           <ul>  
                <li><a href="form-daftar.php">Daftar Baru</a></li>  
                <li><a href="list-siswa.php">Pendaftaran</a></li>  
           </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; ?>  
      </center>  
 </body>  
 </html>  
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());  
 }  
 ?>  

Komentar

Postingan Populer