Skip to main content

UAS PWEB 2018

Untuk UAS Pweb 2018, kami diberi tugas untuk membuat sebuah web PPDB dengan kriteria sebagai berikut
  • Login Aplikasi dengan user  dan password 
  • Mengisi Formulir pendaftaran
  • Edit profil dan biodata calon pendaftar
  • Memilih sekolah tujuan yang dipilih
  • View formulir pendaftaran yang sudah dipermanen
  • Download formulir pendaftaran
Soal : 

  1. Buat rancangan databasenya
  2. Buat rancangan interface aplikasi
  3. Implementasi dan hostingkan
Untuk database nya saya menggunakan 1 tabel untuk menampung semua informasi siswa yang bersangkutan 

Database pialrose_0186 untuk menghandle data siswa 

Database pialrose_0186r untuk menghandle registrasi

Rancangan Interface Aplikasi 

Interface Login dan Sign-Up


Inteface Menu Utama 

Interface Daftar 

Interface Edit 

Interface List Siswa

Interface setelah di hapus beberapa data


Implementasi dan Hostingkan 
Untuk implementasi aplikasi ini, saya meng-hosting kan nya di hosting yang telah saya beli bersama teman saya dengan membuat subdomain di reza.pialrose.com, dapat diakses melalui link berikut : 
PPDB

Source Code 

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

  • download.php
  •  <?php    
      //export.php    
      $connect = mysqli_connect("localhost", "pialrose_rezam", "lada_hitam090499", "pialrose_0186");   
      $output = '';   
      if(isset($_POST["download"]))   
      {   
      $query = "SELECT * FROM calon_siswa";   
      $result = mysqli_query($connect, $query);   
      if(mysqli_num_rows($result) > 0)   
      {   
      $output .= '   
       <table class="table" bordered="1">    
           <tr>    
            <th>ID</th>    
            <th>Nama</th>    
            <th>Alamat</th>   
            <th>Jenis_Kelamin</th>   
            <th>Agama</th>   
            <th>Sekolah_asal</th>   
            <th>Sekolah_pilihan</th>    
           </tr>   
      ';   
      while($row = mysqli_fetch_array($result))   
      {   
       $output .= '   
       <tr>    
            <td>'.$row["id"].'</td>    
            <td>'.$row["nama"].'</td>    
            <td>'.$row["alamat"].'</td>    
            <td>'.$row["jenis_kelamin"].'</td>   
            <td>'.$row["agama"].'</td>   
            <td>'.$row["sekolah_asal"].'</td>   
            <td>'.$row["sekolah_pilihan"].'</td>   
           </tr>   
       ';   
      }   
      $output .= '</table>';   
      header('Content-Type: application/xls');   
      header('Content-Disposition: attachment; filename=download.xls');   
      echo $output;   
      }   
      }   
      ?>   
    

  • errors.php
  •  <?php    
      //export.php    
      $connect = mysqli_connect("localhost", "pialrose_rezam", "lada_hitam090499", "pialrose_0186");   
      $output = '';   
      if(isset($_POST["download"]))   
      {   
      $query = "SELECT * FROM calon_siswa";   
      $result = mysqli_query($connect, $query);   
      if(mysqli_num_rows($result) > 0)   
      {   
      $output .= '   
       <table class="table" bordered="1">    
           <tr>    
            <th>ID</th>    
            <th>Nama</th>    
            <th>Alamat</th>   
            <th>Jenis_Kelamin</th>   
            <th>Agama</th>   
            <th>Sekolah_asal</th>   
            <th>Sekolah_pilihan</th>    
           </tr>   
      ';   
      while($row = mysqli_fetch_array($result))   
      {   
       $output .= '   
       <tr>    
            <td>'.$row["id"].'</td>    
            <td>'.$row["nama"].'</td>    
            <td>'.$row["alamat"].'</td>    
            <td>'.$row["jenis_kelamin"].'</td>   
            <td>'.$row["agama"].'</td>   
            <td>'.$row["sekolah_asal"].'</td>   
            <td>'.$row["sekolah_pilihan"].'</td>   
           </tr>   
       ';   
      }   
      $output .= '</table>';   
      header('Content-Type: application/xls');   
      header('Content-Disposition: attachment; filename=download.xls');   
      echo $output;   
      }   
      }   
      ?>   
    

  • form-daftar.php
  •  <!DOCTYPE html>  
     <html>  
     <head>  
       <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">  
       <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">  
       <style type="text/css">  
         .iconform {  
           float: left;  
           text-align: center;  
           width: 35px;  
           height: 42px;  
           line-height: 40px;  
         }  
       </style>  
     </head>  
     <body>  
       <div class="container m-5">  
           <header>  
              <h3>Formulir Pendaftaran Siswa Baru</h3>  
           </header>  
           <form class="form-horizontal" action="proses-pendaftaran.php" >  
             <div class="form-row">    
               <div class="form-group col-md-5">  
                 <label class="control-label col-xs-3" for="nama">Nama: </label>  
                 <input class="form-control" name="name" id="nama" type="text" placeholder="Nama Lengkap" />  
               </div>   
             </div>  
             <div class="form-row">     
               <div class="form-group col-md-5">  
                 <label class="control-label" for="alamat">Alamat: </label>  
                 <input class="form-control" name="alamat" id="alamat" placeholder="Alamat"></input>  
               </div>  
             </div>  
             <div class="form-group">  
               <div class="form-check form-check-inline">  
                 <input class="form-check-input" type="radio" name="jenis_kelamin" id="jenisL" type="radio" value="Laki-laki">  
                 <label class="iconform"><i class="fas fa-male fa-2x"></i></label>  
               </div>  
               <div class="form-check form-check-inline">  
                 <input class="form-check-input" type="radio" name="jenis_kelamin" id="jenisP" type="radio" value="Perempuan">  
                 <label class="iconform" ><i class="fas fa-female fa-2x"></i></label>  
               </div>   
             </div>   
             <div class="form-group">  
               <label for="agama">Agama: </label>  
                 <select class="form-control col-md-2" name="agama" id="agama" >  
                 <option>Islam</option>  
                 <option>Kristen</option>  
                 <option>Hindu</option>  
                 <option>Budha</option>  
                 <option>Atheis</option>  
                 </select>  
             </div>    
             <div class="form-row">  
               <div class="form-group col-md-5">  
                 <label for="sekolah_asal">Sekolah Asal: </label>  
                 <input class="form-control" name="sekolah_asal" id="sekolah_asal" type="text" placeholder="Nama Sekolah" />  
               </div>  
             </div>  
             <div class="form-row">  
               <div class="form-group col-md-5">  
                 <label for="sekolah_pilihan">Sekolah Pilihan: </label>  
                 <input class="form-control" name="sekolah_pilihan" id="sekolah_pilihan" type="text" placeholder="Sekolah Pilihan" />  
               </div>  
             </div>  
             <div class="form-group">  
               <input class="btn btn-primary" type="button" value="Daftar" name="daftar" onclick="insert()" />  
             </div>   
           </form>  
       </div>  
     </body>  
     </html>  
    

  • form-edit
  •  <?php  
     include("config.php");  
     if( !isset($_GET['id']) ){  
       header('Location: list-siswa.php');  
     }  
     $id = $_GET['id'];  
     $sql = "SELECT * FROM calon_siswa WHERE id=$id";  
     $query = mysqli_query($db, $sql);  
     $siswa = mysqli_fetch_assoc($query);  
     ?>  
     <!DOCTYPE html>  
     <html>  
     <head>   
     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">  
     <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">  
       <style type="text/css">  
        body{  
          background-image: url("download.jpg");  
          background-repeat: no-repeat;  
          background-size: cover;  
        }  
       </style>  
     </head>  
     <body>  
       <div class="container"><br>  
       <h2>Formulit Edit Siswa</h2>  
       <form class="form-horizontal" action="proses-edit.php">  
         <fieldset>  
           <input type="hidden" name="id" value="<?php echo $siswa['id'] ?>" />  
         <div class="form-row">  
           <div class="form group col-md-5">  
             <label class="control-label" for="nama">Nama: </label>  
             <input class="form-control" type="text" id="nama" name="nama" placeholder="Nama Lengkap" value="<?php echo $siswa['nama'] ?>">  
           </div>  
           <div class="col-md-5">  
             <label class="control-label" for="alamat">Alamat: </label>  
             <input class="form-control" id="alamat" name="alamat" value="<?php echo $siswa['alamat'] ?>"></input>  
           </div>  
         </div><br>  
         <div class="form-group">  
           <div class="form-check form-check-inline">  
             <input class="form-check-input" type="radio" name="jenis_kelamin" id="jenisL" type="radio" value="<?php echo ($siswa['jenis_kelamin'] == 'Laki-laki') ? "checked": "" ?>">  
             <label class="iconform"><i class="fas fa-male fa-2x"></i></label>  
           </div>  
           <div class="form-check form-check-inline">  
             <input class="form-check-input" type="radio" name="jenis_kelamin" id="jenisP" type="radio" value="<?php echo ($siswa['jenis_kelamin'] == 'Perempuan') ? "checked": "" ?>">  
             <label class="iconform" ><i class="fas fa-female fa-2x"></i></label>  
           </div>   
         </div>   
         <div class="form-group">  
           <label style="margin-right: 1%" for="agama">Agama: </label>  
             <select class="form-control col-md-2" name="agama" id="agama" >  
               <option>Islam</option>  
               <option>Kristen</option>  
               <option>Hindu</option>  
               <option>Budha</option>  
               <option>Atheis</option>  
             </select>  
         </div>   
         <div class="form-row">  
           <div class="col-md-5">  
              <label for="sekolah_asal">Sekolah Asal: </label>  
             <input class="form-control" id="sekolah_asal" type="text" name="sekolah_asal" placeholder="Sekolah Asal" value="<?php echo $siswa['sekolah_asal'] ?>" />  
           </div>  
         </div>  
         <br>  
         <div class="form-group">  
           <input class="btn btn-primary" type="button" value="Simpan" name="simpan"   
           onclick="update()" />  
         </div>  
         </fieldset>  
       </form>  
       </div>  
     </body>  
     </html>  
     <script type="text/javascript">  
         function update(){  
           var nama = document.getElementById("nama").value;  
           var alamat = document.getElementById("alamat").value;  
           var jenis_kelamin;  
           if(document.getElementById("jenisL").checked){  
             jenis_kelamin = "Laki-laki";  
           }  
           else{  
             jenis_kelamin = "Perempuan";  
           }  
           var agama = document.getElementById("agama").value;  
           var sekolah_asal = document.getElementById("sekolah_asal").value;  
           var sekolah_pilihan = document.getElementById("sekolah_pilihan").value;  
           if(window.XMLHttpRequest){  
             xmlhttp = new XMLHttpRequest();  
           }  
           xmlhttp.onreadystatechange=function(){  
             if(this.readyState==4 && this.status==200){  
               alert(this.responseText);  
               if(this.responseText == "Proses Edit Berhasil") {  
                 window.location.replace("index.php");  
               }  
               else {  
                 alert('GAGAL');   
               }  
             }  
           }  
           xmlhttp.open("GET","proses-edit.php?id=" + <?php echo $id;?> + "&nama=" + nama + "&alamat=" + alamat + "&jenis_kelamin=" + jenis_kelamin + "&agama=" + agama + "&sekolah_asal=" + sekolah_asal + "&sekolah_pilihan=" + sekolah_pilihan, true);  
           xmlhttp.send();  
         }  
     </script>  
    

  • hapus.php
  •  <?php   
     include("config.php");  
      if(isset($_GET['id']) ){  
        // ambil id dari query string  
        $id = $_GET['id'];  
        $sql = "DELETE FROM calon_siswa WHERE id=$id";  
        // buat query hapus    $sql = "DELETE FROM calon_siswa WHERE ID=$id";  
        $query = mysqli_query($db, $sql);  
        // apakah query hapus berhasil?  
        if( $query ){  
          echo "Hapus Data Berhasil";  
        } else {  
          echo "GAGAL";  
        }   
      }   
     ?>  
    

  • index.php
  •  <?php    
      session_start();    
      if (!isset($_SESSION['username'])) {   
         $_SESSION['msg'] = "You must log in first";   
         header('location: login.php');   
      }   
      if (isset($_GET['logout'])) {   
         session_destroy();   
         unset($_SESSION['username']);   
         header("location: login.php");   
      }   
     ?>   
      <!DOCTYPE html>  
     <html>  
     <head>  
       <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">   
       <style type="text/css">  
        body{  
          background-image: url("download.jpg");  
          background-repeat: no-repeat;  
          background-size: cover;  
        }  
       </style>  
     </head>  
     <body >  
       <div class="container-fluid">  
         <header>  
         <h3 align="center">E-Report</h3>  
         </header>  
         <hr>  
         <h4 align="center">Menu</h4>  
         <p align="center"><button class="btn btn-primary" type="button" onclick="showsiswa()">Student List</button></p>  
         <p align="center"><button class="btn btn-primary" onclick="daftar()">Pendaftaran Siswa</button></p>  
       </div>  
        </div>   
       <div class="container-fluid" align="center">   
        <?php if (isset($_SESSION['success'])) : ?>   
        <div class="error success" >   
          <h3>   
        <?php    
           echo $_SESSION['success'];    
           unset($_SESSION['success']);   
        ?>   
          </h3>   
        </div>   
        <?php endif ?>    
        <?php if (isset($_SESSION['username'])) : ?>   
          <p>Welcome <strong><?php echo $_SESSION['username']; ?></strong></p>    
          <p> <a href="index.php?logout='1'" style="color: red;">Logout</a> </p>   
        <?php endif ?>   
       </div>   
       <div class="container" id="demo"></div>  
     </body>  
     </html>  
     <script>  
        function showsiswa() {  
           if (window.XMLHttpRequest) {  
             xhttp = new XMLHttpRequest();  
            }  
           xhttp.onreadystatechange = function() {  
             if (this.readyState == 4 && this.status == 200)  
             {  
              document.getElementById("demo").innerHTML = this.responseText;  
             }  
           };  
          xhttp.open("GET", "list-siswa.php", true);  
          xhttp.send();  
         }  
         function del(id)   
         {  
           if(window.XMLHttpRequest){   
            xmlhttp = new XMLHttpRequest();   
           }  
           xmlhttp.onreadystatechange=function(){  
            if(this.readyState==4 && this.status==200)  
            {  
              alert(this.responseText);   
              showsiswa();   
            }  
           }  
           xmlhttp.open("GET","hapus.php?id=" + id, true);  
           xmlhttp.send();  
         }  
         function daftar() {  
           if (window.XMLHttpRequest) {  
             xhttp = new XMLHttpRequest();  
            }  
           xhttp.onreadystatechange = function() {  
             if (this.readyState == 4 && this.status == 200)  
             {  
              document.getElementById("demo").innerHTML = this.responseText;  
             }  
           };  
          xhttp.open("GET", "form-daftar.php", true);  
          xhttp.send();  
         }  
         function insert(){  
          var nama = document.getElementById("nama").value;  
          var alamat = document.getElementById("alamat").value;  
          var jenis_kelamin;  
          if(document.getElementById("jenisL").checked) {  
           jenis_kelamin = "Laki-laki";  
          }  
          else {  
           jenis_kelamin = "Perempuan";  
          }  
          var agama = document.getElementById("agama").value;  
          var sekolah_asal = document.getElementById("sekolah_asal").value;  
          var sekolah_pilihan = document.getElementById("sekolah_pilihan").value;  
          if(window.XMLHttpRequest) {  
           xmlhttp = new XMLHttpRequest();  
          }  
          xmlhttp.onreadystatechange=function(){  
           if(this.readyState==4 && this.status==200){  
            alert(this.responseText);  
            if(this.responseText == "Pendaftaran Siswa Berhasil") {  
             showsiswa();  
            }  
            else {  
             alert('Pendaftaran Siswa Gagal');   
            }  
           }  
          }  
          xmlhttp.open("GET","proses-pendaftaran.php?nama=" + nama + "&alamat=" + alamat + "&jenis_kelamin=" + jenis_kelamin + "&agama=" + agama + "&sekolah_asal=" + sekolah_asal + "&sekolah_pilihan=" + sekolah_pilihan, true);  
          xmlhttp.send();  
         }  
       </script>  
    

  • list-siswa
  •  <?php include("config.php"); ?>   
      <!DOCTYPE html>   
      <html>   
      <head>   
       <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">   
      </head>   
      <body>   
       <div class="container-fluid">   
        <header>   
         <h3>List Siswa</h3>   
        </header>   
         <table class="table table-bordered border="1px">   
          <tr>   
           <th>No</th>   
           <th>Nama</th>   
           <th>Alamat</th>   
           <th>Jenis Kelamin</th>   
           <th>Agama</th>   
           <th>Sekolah Asal</th>   
           <th></th>   
          </tr>   
         <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['agama']."</td>";   
           echo "<td>".$siswa['sekolah_asal']."</td>";   
           echo "<td>";   
           echo "<a href='form-edit.php?id=".$siswa['id']."' class='btn btn-danger'>Edit</a> | ";  
           echo "<input type='button' onclick=del('".$siswa['id']."') value='Hapus' class='btn btn-info'>";  
           echo "</td>";   
           echo "</tr>";   
          }   
         ?>    
         </tbody>    
         </table>   
        <p>Total Siswa: <?php echo mysqli_num_rows($query) ?></p>   
        <div id="demo"></div>   
       </div>   
     <form method="post" action="download.php">   
        <input type="submit" name="download" class="btn btn-success" value="Download" />  
      </body>   
      </html>   
    

  • login
  •  <?php include('server.php') ?>   
      <!DOCTYPE html>   
      <html>   
      <head>   
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">  
      <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">  
      <title>Registrasi Pendaftaran Siswa</title>   
      <style type="text/css">  
        body{  
          background-image: url("download.jpg");  
          background-repeat: no-repeat;  
          background-size: cover;  
        }  
       </style>   
      </head>   
      <body>   
      <div class="container">   
         <h2>Login</h2>   
       <form class="form-horizontal" method="post" action="login.php">   
         <?php include('errors.php'); ?>   
         <div class="form-row">  
          <div class="col-md-5" >  
           <label align="left">Username</label>   
           <input class="form-control" type="text" name="username" ><br>  
          </div>  
         </div>    
         <div class="form-row">  
          <div class="col-md-5">  
           <label style="padding-left: 5px">Password</label>   
          <input class="form-control" type="password" name="password"><br>  
          </div>  
         </div>     
         <div class="form-group">  
          <button type="submit" class="btn btn-primary" name="login_user" style="margin-left: 10px">Login</button>   
         </div>  
          <p>   
            Belum memiliki akun? <a href="register.php">Sign up</a>   
          </p>   
       </form>  
      </div>    
      </body>   
      </html>  
    

  • proses-edit
  •  <?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['slamat'];   
       $jk = $_POST['jenis_kelamin'];   
       $agama = $_POST['sgama'];   
       $sekolah = $_POST['dekolah_asal'];   
       $sekolahp = $_POST['dekolah_pilihan'];   
       // buat query update   
       $sql = "UPDATE calon_siswa SET nama='$nama', alamat='$alamat', jenis_aelamin='$jk', agama='$agama', sekolah_asal='$sekolah', sekolah_pilihan='$sekolahp' 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...");   
      }   
      ?>   
    

  • proses-pendaftaran
  •  <?php include("config.php");  
         $nama = $_GET['nama'];  
         $alamat = $_GET['alamat'];  
         $jk = $_GET['jenis_kelamin'];  
         $agama = $_GET['agama'];  
         $sekolah_asal = $_GET['sekolah_asal'];  
         $sekolah_pilihan = $_GET['sekolah_pilihan'];  
         $sql = "INSERT INTO calon_siswa (nama, alamat, jenis_kelamin, agama, sekolah_asal, sekolah_pilihan) VALUE ('$nama', '$alamat', '$jk', '$agama', '$sekolah_asal','$sekolah_pilihan')";  
         $query = mysqli_query($db, $sql);  
         if( $query ) {  
           echo "Pendaftaran Siswa Berhasil";  
         } else {  
           echo "GAGAL";  
         }  
     ?>  
    

  • register
  •  <?php include('server.php') ?>   
      <!DOCTYPE html>   
      <html>   
      <head>   
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">  
      <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">  
       <style type="text/css">  
        body{  
          background-image: url("download.jpg");  
          background-repeat: no-repeat;  
          background-size: cover;  
        }  
       </style>   
      </head>   
      <body>   
      <div class="container">   
         <h2>Register</h2>   
       <form class="form-horizontal" method="post" action="register.php">   
          <?php include('errors.php'); ?>   
          <div class="form-row">  
           <div class="col-md-5">  
            <label>Username</label>   
            <input class="form-control" type="text" name="username" value="<?php echo $username; ?>">   
           </div>  
          </div> <br>   
          <div class="form-row">  
           <div class="col-md-5">  
            <label>Email</label>   
          <input class="form-control" type="email" name="email" value="<?php echo $email; ?>">   
           </div>  
          </div><br>  
          <div class="form-row">  
           <div class="col-md-5">  
            <label>Password</label>   
          <input class="form-control" type="password" name="password_1">    
           </div>  
          </div><br>  
          <div class="form-row">  
           <div class="col-md-5">  
            <label>Confirm password</label>   
          <input class="form-control" type="password" name="password_2">   
           </div><br>  
          </div>   
          </div><br>   
          <div class="form-row">   
          <div class="col-md-5">  
           <button style="margin-left: 130px" type="submit" class="btn btn-primary" name="reg_user">Register</button>  
           <p style="margin-left: 130px">Already a member? <a href="login.php">Sign in</a></p>    
          </div>  
          </div>   
       </form>   
      </div>  
      </body>   
      </html>   
    

  • server
  •  <?php   
      session_start();   
      // initializing variables   
      $username = "";   
      $email = "";   
      $errors = array();    
      // connect to the database   
      $db = mysqli_connect('localhost', 'pialrose_reza', 'sayareza1999', 'pialrose_0186r');   
      // REGISTER USER   
      if (isset($_POST['reg_user'])) {   
      // receive all input values from the form   
      $username = mysqli_real_escape_string($db, $_POST['username']);   
      $email = mysqli_real_escape_string($db, $_POST['email']);   
      $password_1 = mysqli_real_escape_string($db, $_POST['password_1']);   
      $password_2 = mysqli_real_escape_string($db, $_POST['password_2']);   
      // form validation: ensure that the form is correctly filled ...   
      // by adding (array_push()) corresponding error unto $errors array   
      if (empty($username)) { array_push($errors, "Username is required"); }   
      if (empty($email)) { array_push($errors, "Email is required"); }   
      if (empty($password_1)) { array_push($errors, "Password is required"); }   
      if ($password_1 != $password_2) {   
        array_push($errors, "The two passwords do not match");   
      }   
      // first check the database to make sure    
      // a user does not already exist with the same username and/or email   
      $user_check_query = "SELECT * FROM users WHERE username='$username' OR email='$email' LIMIT 1";   
      $result = mysqli_query($db, $user_check_query);   
      $user = mysqli_fetch_assoc($result);   
      if ($user) { // if user exists   
       if ($user['username'] === $username) {   
       array_push($errors, "Username already exists");   
       }   
       if ($user['email'] === $email) {   
       array_push($errors, "email already exists");   
       }   
      }   
      // Finally, register user if there are no errors in the form   
      if (count($errors) == 0) {   
         $password = md5($password_1);//encrypt the password before saving in the database   
         $query = "INSERT INTO users (username, email, password)    
              VALUES('$username', '$email', '$password')";   
         mysqli_query($db, $query);   
         $_SESSION['username'] = $username;   
         $_SESSION['success'] = "You are now logged in";   
         header('location: index.php');   
      }   
      }   
      // LOGIN USER   
      if (isset($_POST['login_user'])) {   
      $username = mysqli_real_escape_string($db, $_POST['username']);   
      $password = mysqli_real_escape_string($db, $_POST['password']);   
      if (empty($username)) {   
       array_push($errors, "Username is required");   
      }   
      if (empty($password)) {   
       array_push($errors, "Password is required");   
      }   
      if (count($errors) == 0) {   
       $password = md5($password);   
       $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";   
       $results = mysqli_query($db, $query);   
       if (mysqli_num_rows($results) == 1) {   
       $_SESSION['username'] = $username;   
       $_SESSION['success'] = "You are now logged in";   
       header('location: index.php');   
       }else {   
       array_push($errors, "Wrong username/password combination");   
       }   
      }   
      }   
      ?>   
    

Nama : Reza Adipatria Maranatha
NRP : 05111740000186
Kelas : PWEB C

Comments

Popular posts from this blog

PWEB CURRICULUM VITAE

<!DOCTYPE html> <html lang="en" dir="ltr"> <head> <style type="text/css"> body, html{ height: 100%; margin: 0; } .profil{ border-radius: 50%; } table{ border-spacing: 0; } p{ font-family: TW Cen MT; } img.a{ vertical-align: text-bottom; } img.b{ vertical-align: text-top; } .judul{ font-size: 20px; color: white; } .tulis{ font-size: 15px; color: white; } </style> <title>My Personal Blog</title> </head> <body background="img/Picture1.jpg" style="background-size:cover;"> <br><br><br><br><br> <table width="55%" align="center" style="vertical-align: middle"> <tr> <td

Form Tagihan Air PHP

Nama : Reza Adipatria Maranatha NRP : 05111740000186 Kelas : PWEB C Tugas kali ini saya membuat sebuah form tagihan air yang datanya kita olah dan tampilkan menggunakan PHP atau Hypertext Preprocessor. Berikut hasil dari web saya : Ini adalah tampilan depan form nya Ini merupakan Invoice apabila pelanggan telah melakukan submit form tersebut Source Code Index.php : <!DOCTYPE html> <html> <head> <title>Perusahaan Daerah Air Mandi</title> <link rel="stylesheet" href="test.css"/> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous"> </head> <body> <div class="container"> <div class="leftcontainer">

Tugas Membuat Forms

Tugas kali ini saya membuat sebuah Form Registrasi untuk web berita saya untuk form yang saya buat, saya membuat nya dalam bentuk Modal, yaitu adalah pop-up jika tombol register di klik Berikut adalah hasil dari apa yang saya buat Ini adalah website berita saya Kemudian jika tombol register di klik akan muncul form pop-up Berikut adalah source code nya : HTML: <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href="inicss.css"/> </head> <body> <div class="header"> <h1>PIAL ROSE NEWS</h1> </div> <ul> <li><a class="active" href="#">News</a></li> <li><a href="#">Jobs</a></li> <li><a href="#">