Bootstrap


Arini Indah Nur Fuadah
05111740007003
PWEB C

  1.  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.html
 <!DOCTYPE html>  
 <html>  
 <head>  
  <link href="css/bootstrap.min.css" rel="stylesheet"></link>
      <link href="css/bootstrap.css" rel="stylesheet"></link>
      <script>  
           function loadsiswa() {  
          var xhttp;  
          if (window.XMLHttpRequest) {  
            xhttp = new XMLHttpRequest();  
          }   
          else {  
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");  
          }  
          xhttp.onreadystatechange = function() {  
            if (this.readyState == 4 && this.status == 200) {  
            document.getElementById("tampil").innerHTML = this.responseText;  
            }  
          };  
          xhttp.open("GET", "list-siswa.php", true);  
          xhttp.send();  
        }  
        function daftarsiswa() {  
          var xhttp;  
          if (window.XMLHttpRequest) {  
            xhttp = new XMLHttpRequest();  
          }   
          else {  
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");  
          }  
          xhttp.onreadystatechange = function() {  
            if (this.readyState == 4 && this.status == 200) {  
            document.getElementById("tampil").innerHTML = this.responseText;  
            }  
          };  
          xhttp.open("GET", "form-daftar.php", true);  
          xhttp.send();  
        }  
        function hapus(id) {  
             var xhttp;  
          if (window.XMLHttpRequest) {  
            xhttp = new XMLHttpRequest();  
          }   
          else {  
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");  
          }  
          xhttp.onreadystatechange = function() {  
            if (this.readyState == 4 && this.status == 200) {  
                 alert(this.responseText);  
                 loadsiswa();  
            }  
          };  
          xhttp.open("GET", "hapus.php?id=" + id, true);  
          xhttp.send();  
        }  
      </script>  
 </code></pre>
<body style="text-align: center;">  
   <header>   
    <h2>
Pendaftaran Siswa Baru</h2>
<h4>
MBI Amanatul Ummah</h4>
<img src="mbiicon.png" />     
   </header>   
   <br />
   <button onclick="loadsiswa()" type="button">List Calon Siswa</button>
   <button onclick="daftarsiswa()" type="button">Pendaftaran Siswa</button>  <br />
   <div id="tampil">
       
   </div>
</body>  
 </html>  

  • form-daftar.php
 <!DOCTYPE html>  
 <html>  
 <head>  
 <link rel="stylesheet" type="text/css" href="css.css">  
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">  
   <title>Formulir Pendaftaran Siswa Baru</title>   
  <script type="text/javascript">  
   function tambah() {  
     var nama = document.getElementById("nama").value;  
     var alamat = document.getElementById("alamat").value;  
     var jenis_kelamin;  
     if(document.getElementById("kel_l").checked)  
     {  
      jenis_kelamin = "laki-laki";  
     }  
     else { jenis_kelamin = "perempuan";}  
     var agama = document.getElementById("agama").value;  
     var sekolah_asal = document.getElementById("sekolah_asal").value;  
      var xhttp;  
      if (window.XMLHttpRequest) {  
        xhttp = new XMLHttpRequest();  
      }   
      else {  
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");  
      }  
      xhttp.onreadystatechange = function() {  
        if (this.readyState == 4 && this.status == 200)   
        {  
            alert('Pendaftaran berhasil');   
            loadsiswa();   
        }  
      };  
      xhttp.open("GET", "proses-pendaftaran.php?nama=" + nama + "&alamat=" + alamat + "&jenis_kelamin=" + jenis_kelamin + "&agama=" + agama + "&sekolah_asal=" + "sekolah_asal", true);  
      xhttp.send();  
     }  
  </script>   
      <style>

input[type=text],select,textarea {
    padding: 12px 20px;
    margin: 8px 0;
    box-sizing: border-box;
    width: 50%;
}
</style>
</head>   
   <header>   
    <h2 style="margin: 50px">Formulir Pendaftaran Siswa Baru</h2>  
   </header>   
   <form action="proses-pendaftaran.php" method="POST" style="margin: 50px" class="form-group">       
    <div>
        <label>Nama</label><br>
        <input type="text" placeholder="Nama Pendaftar" name="nama" placeholder="Nama Panjang">
    </div> <br>  
    <div>  
     <label for="jenis_kelamin">Jenis Kelamin </label>
     <label><input type="radio" name="jenis_kelamin" value="laki-laki" id="kel_l" > Laki-laki</label>   
     <label><input type="radio" name="jenis_kelamin" value="perempuan" id="kel_p" > Perempuan</label>   
    </div>  <br> 
    <div>   
     <label for="agama">Agama </label> <br>  
     <select name="agama" id="agama" >   
      <option>Islam</option>     
     </select>   
    </div>  
    <div>  
     <label for="sekolah_asal">Sekolah Asal </label> <br>  
     <input type="text" name="sekolah_asal" placeholder="nama sekolah" id="sekolah_asal" />   
    </div>  
    <div>  
     <label for="alamat">Alamat </label>  <br> 
     <textarea name="alamat" id="alamat" ></textarea>   
    </div>  
    <div>  
     <input type="submit" value="Daftar" name="daftar" onclick="tambah()" />   
    </div>      
  </form>   
 </body>  
 </html>  

  • proses-pendaftaran.php
 <?php  
 include("config.php");  
 if(isset($_POST['daftar'])){  
     $nama = $_POST['nama'];  
     $alamat = $_POST['alamat'];  
     $jk = $_POST['jenis_kelamin'];  
     $agama = $_POST['agama'];  
     $sekolah_asal = $_POST['sekolah_asal'];  
     $sql = "INSERT INTO calon_siswa (nama, alamat, jenis_kelamin, agama, sekolah_asal) VALUE ('$nama', '$alamat', '$jk', '$agama', '$sekolah_asal')";  
     $query = mysqli_query($db, $sql);  
     if( $query ) {  
       header('Location: index.html');  
     }   
     else {  
       echo "Pendaftaran mahasiswa Gagal";  
     }  
   }   
   else {  
     die("Akses dilarang...");  
   }  
 ?>  

  • list-siswa.php
 <?php include("config.php"); ?>  
 <!DOCTYPE html>  
 <html>  
 <head>  
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <link rel="stylesheet" href="css/bootstrap.css"> 
   <title>Pendaftaran Siswa Baru</title>   
   <script>
     function hapus(id) {  
             var xhttp;  
          if (window.XMLHttpRequest) {  
            xhttp = new XMLHttpRequest();  
          }   
          else {  
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");  
          }  
          xhttp.onreadystatechange = function() {  
            if (this.readyState == 4 && this.status == 200) {  
                 alert(this.responseText);  
                 loadsiswa();  
            }  
          };  
          xhttp.open("GET", "hapus.php?id=" + id, true);  
          xhttp.send();  
        } 
   </script>
  </head>   
  <body>  
   <header>   
    <h2>Siswa yang Mendaftar</h2>   
   </header>   
   <br>   
   <table class="table table-hover table-bordered table-striped">   
   <thead>   
    <tr>   
     <th>No</th>   
     <th>Nama</th>   
     <th>Alamat</th>   
     <th>Jenis Kelamin</th>   
     <th>Agama</th>   
     <th>Sekolah Asal</th>   
     <th>Tindakan</th>   
    </tr>   
   </thead>   
   <tbody>   
    <?php   
    $sql = "SELECT * FROM calon_siswa";   
    $query = mysqli_query($db, $sql);   
    $no = 0;  
    while($siswa = mysqli_fetch_array($query)){   
     echo "<tr>";   
     $no++;  
     // echo "<td>".$siswa['id']."</td>";   
     echo "<td>".$no."</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 "<button><a href='form-edit.php?id=".$siswa['id']."'>Edit</a></button> | ";   
     echo "<input type='button' onclick=hapus('".$siswa['id']."') value='Hapus'>";  
     echo "</td>";   
     echo "</tr>";   
    }   
    ?>   
   </tbody>   
   </table>   
   <p>Total: <?php echo mysqli_num_rows($query) ?></p>   
   <div id="tampil"></div>
   </body>  
 </html>  

  • form-edit.php
 <?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);   
  if( mysqli_num_rows($query) < 1 ){   
   die("data tidak ditemukan...");   
  }   
  ?>   
  <!DOCTYPE html>   
  <html>   
  <head>   
  <link rel="stylesheet" type="text/css" href="css.css">  
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">   
   <title>Formulir Edit Mahasiswa | Informatika ITS</title>   
   <script type="text/javascript">  
    function edit(){  
     var nama = document.getElementById("nama").value;  
     var alamat = document.getElementById("alamat").value;  
     var jenis_kelamin;  
     if(document.getElementById("kel_l").checked)  
     {  
      jenis_kelamin = "laki-laki";  
     }  
     else { jenis_kelamin = "perempuan";}  
     var agama = document.getElementById("agama").value;  
     var sekolah_asal = document.getElementById("sekolah_asal").value;  
      var xhttp;  
      if (window.XMLHttpRequest) {  
        xhttp = new XMLHttpRequest();  
      }   
      else {  
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");  
      }  
      xhttp.onreadystatechange = function() {  
        if (this.readyState == 4 && this.status == 200)   
        {  
          alert('Edit Berhasil');  
          loadsiswa();  
        }  
      };  
      xhttp.open("GET", "proses-edit.php?id=" + <?php echo $id; ?> + "&nama=" + nama + "&alamat=" + alamat + "&jenis_kelamin=" + jenis_kelamin + "&agama=" + agama + "&sekolah_asal=" + "sekolah_asal", true);  
      xhttp.send();  
    }  
   </script>   
      <style>
input[type=text],select,textarea {
    padding: 12px 20px;
    margin: 8px 0;
    box-sizing: border-box;
    width: 50%;
}
</style>
  </head> 
  <body>   
   <header>   
    <h2 style="margin: 37px">Formulir Edit Siswa</h2>   
   </header>   
   <form action="proses-edit.php" method="POST" style="margin: 37px">    
     <input type="hidden" name="id" value="<?php echo $siswa['id'] ?>" />   
    <div>   
     <label for="nama">Nama </label>   <br>
     <input type="text" name="nama" id="nama" placeholder="nama lengkap" value="<?php echo $siswa['nama'] ?>" />   
    </div>   
    <br>  
    <div>   
     <label for="jenis_kelamin">Jenis Kelamin </label>   
     <?php $jk = $siswa['jenis_kelamin']; ?>   
     <label><input type="radio" name="jenis_kelamin" value="laki-laki" id="kel_l" <?php echo ($jk == 'laki-laki') ? "checked": "" ?>> Laki-laki</label>   
     <label><input type="radio" name="jenis_kelamin" value="perempuan" id="kel_p" <?php echo ($jk == 'perempuan') ? "checked": "" ?>> Perempuan</label>   
    </div>
    <br>   
    <div>   
     <label for="agama">Agama</label>  <br> 
     <?php $agama = $siswa['agama']; ?>   
     <select id="agama" name="agama">   
      <option <?php echo ($agama == 'Islam') ? "selected": "" ?>>Islam</option>      
     </select>   
    </div>   
    <div>   
     <label for="sekolah_asal">Sekolah Asal </label> <br>  
     <input type="text" id="sekolah_asal" name="sekolah_asal" placeholder="nama sekolah" value="<?php echo $siswa['sekolah_asal'] ?>" />   
    </div> 
    <div>   
     <label for="alamat">Alamat </label>   <br>
     <textarea name="alamat" id="alamat" ><?php echo $siswa['alamat'] ?></textarea>   
    </div> 
    <div>   
     <input type="submit" value="Simpan" name="simpan" onclick="edit()" />   
    </div>      
   </form> 
   </body>  
 </html>  

  • proses-edit.php
 <?php  
 include("config.php");  
 if(isset($_POST['simpan'])){    
   $id = $_POST['id'];   
   $nama = $_POST['nama'];   
   $alamat = $_POST['alamat'];   
   $jk = $_POST['jenis_kelamin'];   
   $agama = $_POST['agama'];   
   $sekolah_asal = $_POST['sekolah_asal'];   
   $sql = "UPDATE calon_siswa SET nama='$nama', alamat='$alamat', jenis_kelamin='$jk', agama='$agama', sekolah_asal='$sekolah_asal' WHERE id=$id";   
   $query = mysqli_query($db, $sql);   
   if( $query ) {   
    // echo "Edit berhasil";  
    header('Location: index.html');   
   } else {   
    die("Gagal menyimpan perubahan...");   
   }   
  }   
  else {   
   die("Akses dilarang...");   
  }  
 ?>  

  • hapus.php
 <?php  
 include("config.php");  
   if( isset($_GET['id']) ){  
   $id = $_GET['id'];  
   $sql = "DELETE FROM calon_siswa WHERE id=$id";  
   $query = mysqli_query($db, $sql);  
   if( $query ){  
     echo "Data Mahasiswa berhasil dihapus"; //list-siswa atau index ?  
   }   
   else {  
     die("gagal menghapus...");  
   }  
 } else {  
   die("akses dilarang...");  
 }   
 ?>  
           
 2. Hasil








Komentar

Postingan populer dari blog ini

Tugas 1 APSI - Analisis Sistem Informasi KASKUS

Analisa Use Case

EAS_PWEB