Selasa, 16 Oktober 2018

ets pweb


Nama : Hafidz Firman Asqalany
NRP   : 05111740000195
Kelas  : PWEB C

1. 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());  
 }  
 ?>  

2. 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'];  
   $semester = $_POST['semester'];  
   $jp = $_POST['jenis_prestasi'];  
   $keterangan = $_POST['keterangan'];  
   // buat query  
   $sql = "INSERT INTO calon_siswa (nama, semester, jenis_prestasi, keterangan) VALUE ('$nama', '$semester', '$jp', '$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...");  
 }  
 ?>  

3.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...");  
 }  
 ?>  

4.index.php

 <!DOCTYPE html>  
 <html>  
 <head>  
   <title>Data Prestasi Siswa</title>  
  </head>   
 <body>  
   <header>  
     <h3>Data Prestasi Siswa</h3>  
     <h1>SMA 30</h1>  
   </header>  
   <h4>Menu</h4>  
   <nav>  
      <?php if(isset($_GET['status'])): ?>  
   <p>  
     <?php  
       if($_GET['status'] == 'sukses'){  
         echo "Pendaftaran siswa baru berhasil!";  
       } else {  
         echo "Pendaftaran gagal!";  
       }  
     ?>  
   </p>  
 <?php endif; ?>  
     <ul>  
       <li><a href="form-daftar.php">input prestasi</a></li>  
       <li><a href="list-siswa.php">prestasi siswa</a></li>  
     </ul>  
   </nav>  
   </body>  
 </html>  

5.list-siswa.php

 <?php include("config.php"); ?>  
 <!DOCTYPE html>  
 <html>  
 <head>  
   <title>Data Prestasi Siswa | SMAN 30</title>  
 </head>  
 <body>  
   <header>  
     <h3>Data Prestasi Siswa</h3>  
   </header>  
   <nav>  
     <a href="form-daftar.php">[+] Tambah prestasi</a>  
   </nav>  
   <br>  
   <table border="1">  
   <thead>  
     <tr>  
       <th>No</th>  
       <th>nama siswa</th>  
       <th>semester</th>  
       <th>jenis prestasi</th>  
       <th>keterangan</th>  
       <th>Tindakan</th>  
     </tr>  
   </thead>  
   <tbody>  
     <?php  
     $sql = "SELECT * FROM calon_siswa";  
     $query = mysqli_query($db, $sql);  
           $nomer = 0;  
     while($siswa = mysqli_fetch_array($query)){  
       echo "<tr>";  
                $nomer++;  
       echo "<td>".$siswa['id']."</td>";  
       echo "<td>".$siswa['nama']."</td>";  
       echo "<td>".$siswa['semester']."</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>Total: <?php echo mysqli_num_rows($query) ?></p>  
   </body>  
 </html>  

6.form-daftar.php

 <!DOCTYPE html>  
 <html>  
 <head>  
   <title>Data Prestasi Siswa</title>  
 </head>  
 <body>  
   <header>  
     <h3>Data Prestasi Siswa</h3>  
   </header>  
   <form action="proses-pendaftaran.php" method="POST">  
     <fieldset>  
     <p>  
       <label for="nama">nama siswa : </label>  
       <input type="text" name="nama" placeholder="nama lengkap" />  
     </p>  
     <p>  
       <label for="semester">semester: </label>  
       <input type="text" name="semester"/>  
     </p>  
     <p>  
       <label for="jenis_prestasi">jenis prestasi: </label>  
       <select name="jenis_prestasi">  
         <option>Teknologi</option>  
         <option>Otomotif</option>  
         <option>Sastra</option>  
         <option>saintek</option>  
         <option>olahraga</option>  
       </select>  
     </p>  
     <p>  
       <label for="keterangan">keterangan: </label>  
       <textarea name="keterangan"></textarea>  
     </p>  
     <p>  
       <input type="submit" value="Simpan" name="simpan" />  
     </p>  
     </fieldset>  
   </form>  
   </body>  
 </html>  

7.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'];  
   $semester = $_POST['semester'];  
   $jp = $_POST['jenis_prestasi'];  
   $keterangan = $_POST['keterangan'];  
   // buat query update  
   $sql = "UPDATE calon_siswa SET nama='$nama', semester='$semester', jenis_prestasi='$jp', 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...");  
 }  
 ?>  

8.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 | SMK Coding</title>  
 </head>  
 <body>  
   <header>  
     <h3>Formulir Edit Siswa</h3>  
   </header>  
   <form action="proses-edit.php" method="POST">  
     <fieldset>  
       <input type="hidden" name="id" value="<?php echo $siswa['id'] ?>" />  
     <p>  
       <label for="nama">nama siswa: </label>  
       <input type="text" name="nama" placeholder="nama lengkap" value="<?php echo $siswa['nama'] ?>" />  
     </p>  
     <p>  
       <label for="semester">semester: </label>  
       <input type="text" name="semester" value="<?php echo $siswa['semester'] ?>" />  
     </p>  
     <p>  
       <label for="jenis_prestasi">jenis prestasi: </label>  
       <?php $jp = $siswa['jenis_prestasi']; ?>  
       <select name="jenis prestasi">  
         <option <?php echo ($jp== 'Teknologi') ? "selected": "" ?>>Teknologi</option>  
         <option <?php echo ($jp== 'Otomotif') ? "selected": "" ?>>Otomotif</option>  
         <option <?php echo ($jp== 'Sastra') ? "selected": "" ?>>Sastra</option>  
         <option <?php echo ($jp== 'Saintek') ? "selected": "" ?>>Saintek</option>  
         <option <?php echo ($jp== 'Olahraga') ? "selected": "" ?>>Olahraga</option>  
       </select>  
     </p>  
           <p>  
       <label for="keterangan">keterangan: </label>  
       <input type="text" name="keterangan" value="<?php echo $siswa['keterangan'] ?>" />  
     </p>  
     <p>  
       <input type="submit" value="Simpan" name="simpan" />  
     </p>  
     </fieldset>  
   </form>  
   </body>  
 </html>  

inilah halaman awal dari source code di atas :

jika ingin menginput prestasi siswa klik menu "input prestasi". setelah klik menu "input prestasi" input data sesuai keinginan anda :




jika ingin melihat data prestasi yang telah dibuat klik menu "prestasi siswa" :



dan ini merupakan tampilan ketika ingin mengedit data prestasi :


dan yang terakhir merupakan ss database saya :

Minggu, 14 Oktober 2018

e-parkir

Nama : Hafidz Firman Asqalany
NRP   : 05111740000195
Kelas  : PBO A


Source code:

 /**  
  * Write a description of class Main here.  
  * program e-parkir  
  * @author (Hafidz Firman Asqalany)  
  * @version (15102018)  
  */  
 import java.util.Scanner;  
 public class Main  
 {  
   private static int b_parkir;  
   public static void main(String args[]){  
     Scanner input=new Scanner(System.in);  
     int jam_parkir,kendaraan=0;  
     String nopol;  
     int sepeda=1000;  
     int motor=2000;  
     int mobil=3000;  
     System.out.println("Welcome to e-parkir");  
     System.out.println("Silahkan masukkan jenis kendaraan anda");  
     System.out.println("1. Motor");  
     System.out.println("2. Mobil");  
     System.out.println("3. sepeda");  
     kendaraan=input.nextInt();  
     if(kendaraan==1){  
       System.out.println("Silahkan masukkan nomor plat anda");  
       nopol=input.next();  
       System.out.println("Tentukan Durasi Parkir");  
       jam_parkir=input.nextInt();  
       if(jam_parkir==1){  
         b_parkir=motor;  
         System.out.println("anda harus membayar " +b_parkir);  
         System.out.println("tempelkan kartu pembayaran anda");  
       }  
       else if(jam_parkir>=2){  
         b_parkir=jam_parkir*motor;  
         System.out.println("anda harus membayar " +b_parkir);  
         System.out.println("tempelkan kartu pembayaran anda");  
       }  
       System.out.println("===============");  
       System.out.println("e-parkir");  
       System.out.println("##ini karcis anda##");  
       System.out.println("nopol anda:"+nopol);  
       System.out.println("total biaya " +b_parkir);  
       System.out.println("===============");  
     }  
     if(kendaraan==2){  
       System.out.println("Silahkan masukkan nomor plat anda");  
       nopol=input.next();  
       System.out.println("Tentukan Durasi Parkir");  
       jam_parkir=input.nextInt();  
       if(jam_parkir==1){  
         b_parkir=mobil;  
         System.out.println("anda harus membayar " +b_parkir);  
         System.out.println("tempelkan kartu pembayaran anda");  
       }  
       else if(jam_parkir>=2){  
         b_parkir=jam_parkir*mobil;  
         System.out.println("anda harus membayar " +b_parkir);  
         System.out.println("tempelkan kartu pembayaran anda");  
       }  
       System.out.println("===============");  
       System.out.println("e-parkir");  
       System.out.println("##ini karcis anda##");  
       System.out.println("nopol anda: "+nopol);  
       System.out.println("total biaya " +b_parkir);  
       System.out.println("===============");  
     }  
     if(kendaraan==3){  
       System.out.println("Tentukan Durasi Parkir");  
       jam_parkir=input.nextInt();  
       if(jam_parkir==1){  
         b_parkir=sepeda;  
         System.out.println("anda harus membayar " +b_parkir);  
         System.out.println("tempelkan kartu pembayaran anda");  
       }  
       else if(jam_parkir>=2){  
         b_parkir=jam_parkir*sepeda;  
         System.out.println("anda harus membayar " +b_parkir);  
         System.out.println("tempelkan kartu pembayaran anda");  
       }  
       System.out.println("===============");  
       System.out.println("e-parkir");  
       System.out.println("##ini karcis anda##");  
       System.out.println("total biaya " +b_parkir);  
       System.out.println("===============");  
     }  
   }  
 }  

hasilnya :

Jumat, 12 Oktober 2018

Membuat aplikasi TechSupport

Nama  : Hafidz Firman Asqalany
NRP    : 05111740000195
Kelas   : PBO A

Source Code Support System :

 public class SupportSystem    
  {    
  private InputReader reader;    
  private Responder responder;    
  public SupportSystem()    
  {    
  reader = new InputReader();    
  responder = new Responder();    
  }    
  public void start()    
  {    
  boolean finished = false;    
  printWelcome();    
  while(!finished) {    
  String input = reader.getInput();    
  if(input.startsWith("bye")) {    
  finished = true;    
  }    
  else {    
  String response = responder.generateResponse();    
  System.out.println(response);    
  }    
  }    
  printGoodbye();    
  }    
  private void printWelcome()    
  {    
  System.out.println(    
  "Welcome to fake Cortana");    
  System.out.println();    
  System.out.println("What Can I do for you? ");    
  System.out.println(    
  "Please tell us about your problem.");  
  System.out.println(    
  "type 'goodbye/bye' to end this program.");  
  }    
  private void printGoodbye()    
  {    
  System.out.println("Thanks for using me.");    
  }    
  }    

Source Code Input Reader :

 import java.util.Scanner;    
  public class InputReader    
  {    
   public String getInput()    
   {    
   Scanner input = new Scanner(System.in);    
   String in = input.nextLine();    
   return in;    
   }    
  }    

Source Code Reader :

 public class Responder    
  {    
   public Responder()    
   {    
   }    
   public String generateResponse()    
   {    
   return "zzzzz";    
   }    
  }    


Rabu, 10 Oktober 2018

Membuat Form Pendaftaran Menggunakan SQL dan PHP

Nama : Hafidz Firman Asqalany
NRP   : 05111740000195
Kelas  : PWEB C

Source Code yang dibutuhkan untuk membuat Form pendaftaran adalah sebagai berikut ;

1. config.php (untuk menyimpan konfigurasi database)

 <?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());  
 }  
 ?>  

2. index.php (halaman utama)

 <!DOCTYPE html>  
 <html>  
 <head>  
   <title>Pendaftaran Siswa Baru |SMAN 30</title>  
  </head>   
 <body>  
   <header>  
     <h3>Pendaftaran Siswa Baru</h3>  
     <h1>SMAN 30</h1>  
   </header>  
   <h4>Menu</h4>  
   <nav>  
      <?php if(isset($_GET['status'])): ?>  
   <p>  
     <?php  
       if($_GET['status'] == 'sukses'){  
         echo "Pendaftaran siswa baru berhasil!";  
       } else {  
         echo "Pendaftaran gagal!";  
       }  
     ?>  
   </p>  
 <?php endif; ?>  
     <ul>  
       <li><a href="form-daftar.php">Daftar Baru</a></li>  
       <li><a href="list-siswa.php">Pendaftar</a></li>  
     </ul>  
   </nav>  
   </body>  
 </html>  

3. list-siswa.php (halaman untuk menampilkan data siswa)

 <?php include("config.php"); ?>  
 <!DOCTYPE html>  
 <html>  
 <head>  
   <title>Pendaftaran Siswa Baru | SMAN 30</title>  
 </head>  
 <body>  
   <header>  
     <h3>Siswa yang sudah mendaftar</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>Agama</th>  
       <th>Sekolah Asal</th>  
       <th>Tindakan</th>  
     </tr>  
   </thead>  
   <tbody>  
     <?php  
     $sql = "SELECT * FROM calon_siswa";  
     $query = mysqli_query($db, $sql);  
           $nomer = 0;  
     while($siswa = mysqli_fetch_array($query)){  
       echo "<tr>";  
                $nomer++;  
                echo "<td>".$nomer."</td>";  
       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']."'>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>  
   </body>  
 </html>  

4. form-daftar.php (halaman formulir pendaftaran)

 <!DOCTYPE html>  
 <html>  
 <head>  
   <title>Formulir Pendaftaran Siswa Baru | SMK Coding</title>  
 </head>  
 <body>  
   <header>  
     <h3>Formulir Pendaftaran Siswa Baru</h3>  
   </header>  
   <form action="proses-pendaftaran.php" method="POST">  
     <fieldset>  
     <p>  
       <label for="nama">Nama: </label>  
       <input type="text" name="nama" placeholder="nama lengkap" />  
     </p>  
     <p>  
       <label for="alamat">Alamat: </label>  
       <textarea name="alamat"></textarea>  
     </p>  
     <p>  
       <label for="jenis_kelamin">Jenis Kelamin: </label>  
       <label><input type="radio" name="jenis_kelamin" value="laki-laki"> Laki-laki</label>  
       <label><input type="radio" name="jenis_kelamin" value="perempuan"> Perempuan</label>  
     </p>  
     <p>  
       <label for="agama">Agama: </label>  
       <select name="agama">  
         <option>Islam</option>  
         <option>Kristen</option>  
         <option>Hindu</option>  
         <option>Budha</option>  
         <option>Atheis</option>  
       </select>  
     </p>  
     <p>  
       <label for="sekolah_asal">Sekolah Asal: </label>  
       <input type="text" name="sekolah_asal" placeholder="nama sekolah" />  
     </p>  
     <p>  
       <input type="submit" value="Daftar" name="daftar" />  
     </p>  
     </fieldset>  
   </form>  
   </body>  
 </html>  

5. proses-pendaftaran.php (skrip yang memproses pendaftaran)

 <?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'];  
   $agama = $_POST['agama'];  
   $sekolah = $_POST['sekolah_asal'];  
   // buat query  
   $sql = "INSERT INTO calon_siswa (nama, alamat, jenis_kelamin, agama, sekolah_asal) VALUE ('$nama', '$alamat', '$jk', '$agama', '$sekolah')";  
   $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...");  
 }  
 ?>  

6. form-edit.php (form untuk edit data siswa)

 <?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 | SMK Coding</title>  
 </head>  
 <body>  
   <header>  
     <h3>Formulir Edit Siswa</h3>  
   </header>  
   <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="agama">Agama: </label>  
       <?php $agama = $siswa['agama']; ?>  
       <select name="agama">  
         <option <?php echo ($agama == 'Islam') ? "selected": "" ?>>Islam</option>  
         <option <?php echo ($agama == 'Kristen') ? "selected": "" ?>>Kristen</option>  
         <option <?php echo ($agama == 'Hindu') ? "selected": "" ?>>Hindu</option>  
         <option <?php echo ($agama == 'Budha') ? "selected": "" ?>>Budha</option>  
         <option <?php echo ($agama == 'Atheis') ? "selected": "" ?>>Atheis</option>  
       </select>  
     </p>  
     <p>  
       <label for="sekolah_asal">Sekolah Asal: </label>  
       <input type="text" name="sekolah_asal" placeholder="nama sekolah" value="<?php echo $siswa['sekolah_asal'] ?>" />  
     </p>  
     <p>  
       <input type="submit" value="Simpan" name="simpan" />  
     </p>  
     </fieldset>  
   </form>  
   </body>  
 </html>  

7. proses-edit.php (skrip untuk memproses edit/update)

 <?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'];  
   $agama = $_POST['agama'];  
   $sekolah = $_POST['sekolah_asal'];  
   // buat query update  
   $sql = "UPDATE calon_siswa SET nama='$nama', alamat='$alamat', jenis_kelamin='$jk', agama='$agama', sekolah_asal='$sekolah' 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...");  
 }  
 ?>  

8. hapus.php (skrip untuk menghapus data dari database)

 <?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...");  
 }  
 ?>  

hasil jika semua source code di atas dijalankan :

Tampilan halaman utama akan menjadi seperti ini












jika ingin Menambahkan Data ke Tabel MySQL klik menu Daftar Baru. setelah mengisi data yang di inginkan klik menu daftar . Hasilnya akan tampak seperti ini






jika anda ingin melihat data yang telah di buat, anda bisa klik menu pendaftar.


anda bisa menghapus data yang ada dengan cara klik menu hapus.




 jika ingin mengedit data yang telah dibuat, anda bisa klik menu edit dan hasilnya akan tampak seperti ini






Selasa, 09 Oktober 2018

Membuat form pembayaran Listrik Beserta invoice

Nama : Hafidz Firman Asqalany
NRP   : 05111740000195
Kelas  : PWEB C

Source code untuk form registrasi :

 <?php  
  session_start();  
 ?>  
 <!DOCTYPE html>  
  <head>  
  <style type="text/css">  
  body  
  {  
       background:#D3D3D3;  
       font-family:arial;  
  }  
  #wrapshopcart  
  {  
       width:50%;  
       margin:3em auto;  
       padding:30px;  
       background:#fff;  
       box-shadow:0 0 15px #ddd;  
  }  
  h1  
  {  
       margin:0;  
       padding:0;  
       font-size:2.5em;  
       font-weight:bold;  
  }  
  p  
  {  
       font-size:1em;  
       margin:0;  
  }  
  table  
  {  
       margin:2em 0 0 0;  
       border:1px solid #eee;  
       width:100%;  
       border-collapse: separate;  
       border-spacing:0;  
  }  
  table th  
  {  
       background:#fafafa;  
       border:none;  
       padding:20px ;  
       font-weight:normal;  
       text-align:left;  
  }  
  table td  
  {  
       background:#fff;   
       border:none;  
       padding:12px 20px;   
       font-weight:normal;  
       text-align:left;   
       border-top:1px solid #eee;  
  }  
  table tr.total td  
  {  
       font-size:1.5em;  
  }  
  .btnsubmit  
  {  
       display:inline-block;  
       padding:10px;  
       border:1px solid #ddd;  
       background:#eee;  
       color:#000;  
       text-decoration:none;  
       margin:2em 0;  
  }  
  form  
  {  
       margin:2em 0 0 0;  
  }  
  label  
  {  
       display:inline-block;  
       width:12em;  
  }  
  input[type=text]  
  {  
       border:1px solid #bbb;  
       padding:10px;  
       width:30em;  
  }  
  textarea  
  {  
       border:1px solid #bbb;  
       padding:10px;  
       width:30em;  
       height:5em;  
       vertical-align:text-top;  
       margin:0.3em 0 0 0;  
  }  
  .submitbtn  
  {  
     position:relative;  
     box-sizing:border-box;  
     display:block;  
     width:100px;  
     border: 0px none;  
     padding: 0px 15px;  
     text-align:center;  
     font-family:Century;  
     font-weight:400;  
     text-shadow: 0px 0px 0px transparent;  
     border-radius: 4px;  
     color:#FFF;  
     background:#000000 none repeat scroll 0% 0%;  
     height: 30px;  
     line-height: 29px;  
     font-size: 16px;  
     margin:auto;  
     margin-top:10px;  
     }  
        .reset{  
     position:relative;  
     box-sizing:border-box;  
     display:block;  
     width:100px;  
     border: 0px none;  
     padding: 0px 15px;  
     text-align:center;  
     font-family:Century;  
     font-weight:400;  
     text-shadow: 0px 0px 0px transparent;  
     border-radius: 4px;  
     color:#FFF;  
     background:#b22222 none repeat scroll 0% 0%;  
     height: 30px;  
     line-height: 29px;  
     font-size: 16px;  
     margin:auto;  
     margin-top:10px;  
     }  
  };  
  </style>  
  </head>  
  <body>  
  <div id="wrapshopcart">  
   <h1>Form Registrasi</h1>  
      <script type="text/javascript">  
      function validasi_input(form)  
      {  
        pola_email=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
        pola_nopel=/^[0-9\_\-]{6,100}$/;  
           if (form.nama_depan.value == "")  
           {  
                alert("Nama depan anda masih kosong.");  
                form.nama_depan.focus();  
                return (false);  
           }  
           else if (form.nama_belakang.value =="")  
           {  
                alert ("Nama belakang anda masih kosong.");  
                form.nama_belakang.focus();  
                return false;  
           }  
           else if (!pola_email.test(form.email.value))  
           {  
                alert ('Penulisan Email tidak valid.');  
                form.email.focus();  
                return false;  
           }  
           else if (!pola_nopel.test(form.no_pel.value))  
           {  
                alert ('Nomor pelanggan terdiri dari 6 angka.');  
                form.no_pel.focus();  
                return false;  
           }  
           else if (form.alamat.value == "")  
           {  
                alert("Alamat anda masih kosong");  
                form.alamat.focus();  
                return (false);  
           }  
      return (true);  
      }  
      </script>  
   <form action="invoice.php" method="POST" onsubmit="return validasi_input(this)">  
   <label>Nama Depan : <input type="text" name="nama_depan" class="inputan" /></label><table></table>  
   <label>Nama Belakang : <input type="text" name="nama_belakang" class="inputan" /></label><table></table>  
   <label>Email : <input type="text" name="email" class="inputan" /></label><table></table>  
   <label>No Pelanggan : <input type="text" name="no_pel" class="inputan" /></label><table></table>  
   <label>No Telp : <input type="text" name="no_telp" class="inputan" /></label><table></table>  
   <label>Alamat :<textarea name="alamat" class="textan"></textarea></label><table></table>  
   <input type="submit" name="kirim" value="Submit" class="submitbtn" />  
   </form>  
  </div>  
  </body>  
 </html>  

Source Code untuk Invoice :

 <?php  
  session_start();  
  $total = NULL;  
  $post = $_POST;  
  /* untuk invoice bisa di ambil dari database, karena pada dasarnya invoice tidak akan pernah recordnya itu di delete */  
  /* berapa jumlah invoice kemudian di tambahkan 1 */  
  $numrows_invoice_db = 565;  
  $invoice = $numrows_invoice_db + 7;  
 ?>  
 <!DOCTYPE html>  
  <head>  
  <style type="text/css">  
  body  
  {  
       background:#efefef;  
       font-family:arial;  
   }  
  #wrapshopcart  
  {  
       width:70%;  
       margin:3em auto;  
       padding:30px;  
       background:#fff;  
       box-shadow:0 0 15px #ddd;  
   }  
  h1  
  {  
       margin:0;  
       padding:0;  
       font-size:2.5em;  
       font-weight:bold;  
   }  
  p  
  {  
       font-size:1em;  
       margin:0;  
   }  
  table  
  {  
       margin:2em 0 0 0;  
       border:1px solid #eee;  
       width:100%;   
       border-collapse: separate;  
       border-spacing:0;  
   }  
  table th  
  {  
       background:#fafafa;  
       border:none;  
       padding:20px ;  
       font-weight:normal;  
       text-align:left;  
   }  
  table td  
  {  
       background:#fff;   
       border:none;   
       padding:12px 20px;  
       font-weight:normal;  
       text-align:left;   
       border-top:1px solid #eee;  
   }  
  table tr.total td  
  {  
       font-size:1.5em;  
   }  
  .btnsubmit  
  {  
       display:inline-block;  
       padding:10px;  
       border:1px solid #ddd;  
       background:#eee;  
       color:#000;  
       text-decoration:none;  
       margin:2em 0;  
   }  
  form  
  {  
       margin:2em 0 0 0;  
   }  
  label  
  {  
       display:inline-block;  
       width:auto;  
   }  
  input[type=text]  
  {  
       border:1px solid #bbb;  
       padding:10px;  
       width:30em;  
   }  
  textarea  
  {  
       border:1px solid #bbb;  
       padding:10px;  
       width:30em;  
       height:5em;  
       vertical-align:text-top;  
       margin:0.3em 0 0 0;  
   }  
  .submitbtn  
  {  
       font-size:1.5em;  
       display:inline-block;  
       padding:10px;  
       border:1px solid #ddd;  
       background:#eee;  
       color:#000;  
       text-decoration:none;  
       margin:0.5em 0 0 8em;  
  }  
  </style>  
  </head>  
  <body>  
   <div id="wrapshopcart">  
   <h1>Invoice <?php echo $invoice;?></h1>  
   <p>Silahkan save halaman ini. </p>  
   <h3>Berikut adalah data lengkap Anda : </h3>  
   </label><table><tr></tr></table>  
   <label>Nama Lengkap : <?php echo $post['nama_depan'] . ' ' . $post['nama_belakang'] ;?> </label><table><tr></tr></table>  
   <label>Email : <?php echo $post['email'] ;?> </label><table><tr></tr></table>  
   <label>No Pelanggan: <?php echo $post['no_pel'] ;?></label><table><tr></tr></table>  
   <label>No Telp : <?php echo $post['no_telp'] ;?></label><table><tr></tr></table>  
   <label>Alamat : <?php echo $post['alamat'] ;?></label><table><tr></tr></table>  
   <h3>Total tagihan anda: </h3>  
   <table>  
   <tr><th width="70%">Produk</th><th width="10%">Quantity</th><th width="20%">Jumlah</th></tr>  
   <?php foreach($_SESSION['cart'] as $row):?>  
    <?php   
    $jumlah = $_SESSION['price'][$row['productid']] * $row['qty'];   
    $total += $jumlah;  
    ?>  
    <tr><td><?php echo $row['product'];?></td><td><?php echo $row['qty'];?></td><td><?php echo $jumlah; ?></td></tr>  
   <?php endforeach;?>  
   <tr class="total"><td></td><td >Total</td><td><?php echo $total;?></td></tr>  
   </table>    
   <h3>Silahkan Lakukan Pembayaran sebelum jatuh tempo</h3>  
  </div>  
  </body>  
 </html>  

tampilan dari source code di atas :




Minggu, 07 Oktober 2018

program lelang

 Nama  : Hafidz Firman Asqalany
 NRP    : 05111740000195
 Kelas   : PBO A

Kali ini saya disuruh membuat program lelang. berikut saya tunjukkan source codenya :

1. Auction :

 /**    
  * A classto model an item an item (or set of items) in an auction: a lot.    
  *    
  * @author (Hafidz Firman Asqalany)    
  * @version (4.1.3)    
  */    
  import java.util.ArrayList;    
  import java.util.Iterator;    
  public class Auction    
  {    
   // The List of Lots in this auction.    
   private ArrayList<Lot> lots;    
   // The number that will be given to the next lot entered    
   // into this auction    
   private int nextLotNumber;    
   /**    
   * Create a new auction    
   */    
   public Auction()    
   {    
   lots = new ArrayList<Lot>();    
   nextLotNumber = 1;    
   }    
   /**    
   * Enter a new lot into the auction.    
   * @param description A description of the lot.    
   */    
   public void enterLot(String description)    
   {    
   lots.add(new Lot(nextLotNumber, description));    
   nextLotNumber++;    
   }    
   /***    
   * Show the full list of lots in this auction.    
   */    
   public void showLots()    
   {    
   for(Lot lot : lots){    
    System.out.println(lot.toString());    
   }    
   }    
   /**    
   * Bid for a lot.    
   * A message indicating whether the bid is succesful or not is printed.    
   * @param number The lot number being bid for.    
   * @param bidder The person bidding for the lot.    
   * param value The value of the bid.    
   */    
   public void bidFor(int lotNumber, Person bidder, long value)    
   {    
   Lot selectedLot = getLot(lotNumber);    
   if(selectedLot!=null){    
    boolean successful = selectedLot.bidFor(new Bid(bidder,value));    
    if (successful) {    
    System.out.println("The bid for lot number " + lotNumber +    
    " was successful.");    
    }    
    else {    
    //Report which bid is higher.    
    Bid highestBid = selectedLot.getHighestBid();    
    System.out.println("Lot number: " + lotNumber +    
    " already has a bid of: " + highestBid.getValue());    
    }    
   }    
   }    
   /**    
   * Return a list of the unsold lots.    
   */    
   public void close()    
   {    
   System.out.println("The auction is closed.");    
   for(Lot lot : lots) {    
    System.out.println(lot.getNumber() + ": " +lot.getDescription());    
    Bid bid = lot.getHighestBid();    
    if (bid==null){    
    System.out.println("(No Bids for this lot.)");    
    }    
    else {    
    System.out.println( "sold to " +    
    bid.getBidder().getName() + " for "    
    + bid.getValue());    
   }    
   }    
  }    
   /**    
   * Return the lot with the given number.    
   * Return null if a lot with this number does not exist.    
   * @param lotNumber The number of the lot to return.    
   */    
   public Lot getLot(int lotNumber)    
   {    
   if((lotNumber >= 1) && (lotNumber < nextLotNumber)) {    
    // The number seems to be reasonable.    
    Lot selectedLot = lots.get(lotNumber - 1);    
    // Include a confidence check to be sure we have the right lot.    
    if(selectedLot.getNumber() != lotNumber) {    
    System.out.println("Internal error: lot number " +    
    selectedLot.getNumber() + " was returned instead of " +    
    lotNumber);    
    // Don't return invalid lot.    
    selectedLot = null;    
    }    
    return selectedLot;    
    }    
   else {    
    System.out.println("lot number: " + lotNumber + " does not exist.");    
    return null;    
    }    
   }    
   }    

2. Lot :

 /**    
  * A classto model an item an item (or set of items) in an auction: a lot.    
  *    
  * @author (Hafidz Firman Asqalany)    
  * @version (4.1.3)    
  */    
  public class Lot    
  {    
   // A unique identifying number.    
   private final int number;    
   //A description of the lot.    
   private String description;    
   // The current highest bid for this lot.    
   private Bid highestBid;    
   /**    
   * Construct a Lot, setting its number and description.    
   * @param number The lot number.    
   * @param description A description of this lot.    
   */    
   public Lot(int number, String description)    
   {    
   this.number = number;    
   this.description = description;    
   }    
   /**    
   * Attempt to bid for this lot. A successful bid    
   * must have a value higher than any existing bid.    
   * @param bid A new bid.    
   * @return true if successful, false otherwise.    
   */    
   public boolean bidFor(Bid bid)    
   {    
   if((highestBid == null)||(bid.getValue() > highestBid.getValue()))    
   {    
    // This bid is the best so far    
    highestBid = bid;    
    return true;    
   }    
   else{    
    return false;    
   }    
   }    
   /**    
   * @return A string representation of this lot's details.    
   */    
   public String toString()    
   {    
   String details = number + ": " + description;    
   if(highestBid!=null) {    
    details+= " Bid: " +highestBid.getValue();    
   }    
   else {    
    details += " (No bid)";    
   }    
   return details;    
   }    
   /**    
   * @return The lot's number.    
   */    
   public int getNumber()    
   {    
   return number;    
   }    
   /**    
   * @return The lot's description.    
   */    
   public String getDescription()    
   {    
   return description;    
   }    
   /**    
   * @return The highest bid for this lot.    
   * This could be null if there is no current bid.    
   */    
   public Bid getHighestBid()    
   {    
   return highestBid;    
   }    
  }    

3. Person :

 /**    
  * A classto model an item an item (or set of items) in an auction: a lot.    
  *    
  * @author (Hafidz Firman Asqalany)    
  * @version (4.1.3)    
  */    
  public class Person    
  {    
   // The name of this person.    
   private final String name;    
   /**    
   * Create a new person with the given name.    
   * @param name The person's name.    
   */    
   public Person(String name)    
   {    
   this.name = name;    
   }    
   /**    
   * @return The Person's name*    
   */    
   public String getName()    
   {    
   return name;    
   }    
  }    

4. Bid :

 /**    
  * A classto model an item an item (or set of items) in an auction: a lot.    
  *    
  * @author (Hafidz Firman Asqalany)    
  * @version (4.1.3)    
  */    
  public class Bid    
  {    
   // The person making the bid    
   private final Person bidder;    
   // The value of the bid. This could be a large number so the long type has been used    
   private final long value;    
   /**    
   * Create a bid    
   * @param bidder Who is bidding for the lot.    
   * @param value The value of the bid.    
   */    
   public Bid(Person bidder, long value)    
   {    
   this.bidder = bidder;    
   this.value = value;    
   }    
   /**    
   *@return The bidder.    
   */    
   public Person getBidder()    
   {    
   return bidder;    
   }    
   /**    
   * @return The value of the bid.    
   */    
   public long getValue()    
   {    
   return value;    
   }    
  }    

Dan ini merupakan hasil dari eksekusi program :



Selasa, 02 Oktober 2018

membuat form validasi dengan javascript

Nama : Hafidz Firman Asqalany
NRP   : 05111740000195
Kelas  : PWEB C

Souce codenya :

 <!DOCTYPE html>   
  <html>   
  <head>   
    <title>Membuat Form Validasi dengan Javascript</title>   
    <meta charset="utf-8">   
    <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>   
    <meta name="viewport" content="width=device-width, initial-scale=1"/>   
    <style type="text/css">   
    body {   
       background-image:url(THUMBNAIL_BG_03.jpg);   
      background-size:cover}  
       font-family: sans-serif;   
    }   
    h2 {   
       color: #fff;   
    }   
    .login {   
       padding: 1em;   
       margin: 2em auto;   
       width: 17em;   
       background: #7B68EE;   
       border-radius: 3px;   
    }   
    label {   
       font-size: 10pt;   
       color: #555;   
    }   
    input[type="text"],   
    input[type="email"],   
    textarea {   
       padding: 8px;   
       width: 95%;   
       background: #efefef;   
       border: 0;   
       font-size: 10pt;   
       margin: 6px 0px;   
    }   
    .tombol {   
       background: #000000;   
       color: #fff;   
       border: 0;   
       padding: 5px 8px;   
    }   
  </head>   
  </style>   
  <body>   
  <script type="text/javascript">   
    function validasi_input(form){   
     var mincar = 50;   
     var mincar1 = 10;   
    var mincar2 = 12;   
    pola_email=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;   
    pola_tanggal=/^d{1,2}\/\d{1,2}\/\d{4}$/;   
     if (form.nama.value.length > mincar && form.nama.value.length !=0){   
     alert("Panjang nama maksimal 50 Karater!");   
     form.nama.focus();   
     return (false);   
     }   
     else if (form.nama.value == ""){   
     alert("Name masih kosong!");   
     form.nama.focus();   
     return (false);   
     }   
     else if (!pola_email.test(form.email.value)){   
     alert ("Penulisan Email tidak benar");   
     form.email.focus();   
     return (false);   
     }      
     else if (form.nohp.value.length < mincar1 || form.nohp.value.length > mincar2){   
     alert("Panjang No.handphone Minimal 10 Karater dan Maksimal 12 Karater!");   
     form.nohp.focus();   
     return (false);   
     }   
     else if (!pola_tanggal.test(form.tgllahir.value)){   
     alert ("Penulisan Tanggal Lahir harus sesuai format dd/mm/yyyy");   
     form.tgllahir.focus();   
     return (false);   
     }    
  return (true);   
  }   
  </script>   
    <div class="login">   
       <form method="post" action="aksi.php" onsubmit="return validasi_input(this)">   
 <title>Membuat Form Validasi dengan Javascript </title>  
         <div>   
            <label>Nama: <input type="text" name="nama" id="nama" placeholder="Tuliskan nama anda" /></label>   
         </div>   
         <div>  
                     <label>Alamat:</label>  
                    <td>  
                      <textarea class="alamat" type="textarea" name="Nama Jalan" id="textarea" placeholder="Nama Jalan" cols="35" rows="1"></textarea>  
                    </td>  
                    <tr>  
                     <td>     
                     </td>  
                 <td>  
                        <textarea class="alamat" type="textarea" name="No" id="textarea" placeholder="No" cols="35" rows="1"></textarea>  
                 </td>  
                    </tr>  
                    <tr>  
                 <td>     
                     </td>  
                 <td>  
                        <textarea class="alamat" type="textarea" name="Kota" id="textarea" placeholder="Kota" cols="35" rows="1"></textarea>  
                 </td>  
                    </tr>  
                  </tr>  
                </div>  
         <div>   
            <label>Email:</label>   
            <input type="email" name="email" id="email" placeholder="example@gmail.com" />   
         </div>   
         <div>   
            <label>No.HP:</label>   
            <input type="text" name="nohp" id="nohp" placeholder="08xxxxxxxxxx" />   
         </div>   
         <div>   
            <div>   
            <label>Jenis Kelamin: </label> <br/>   
            <input type="radio" name="gender" value="male" /> Laki-Laki   
            <input type="radio" name="gender" value="female" /> Perempuan  
         </div>   
         <div>   
            <label>Tanggal Lahir:</label>   
            <input type="text" name="tgllahir" id="tgllahir" placeholder="dd/mm/yyyy" />   
         </div>   
         <div>   
            <label>Rubik Yang Disukai: <select name="rubik"></label>  
            <option value="pilih" selected>--Pilih--</option>    
         <option value="opini">Opini</option>   
         <option value="olahraga">Olahraga</option>   
         <option value="ekonomi">Ekonomi</option>   
         <option value="politik">Politik</option>   
         <option value="sosial">Sosial</option>   
         <option value="bisnis">Bisnis</option>   
         <option value="kesehatan">Kesehatan</option>   
         <option value="pendidikan">Pendidikan</option>   
         <option value="teknologi">Teknologi</option>   
         <option value="seni">Entertain dan Seni</option>   
         </select>   
         </div>   
         <div>   
            <input type="submit" value="Daftar" class="tombol">   
         </div>   
       </form>   
    </div>   
  </body>   
  </html>   

Hasilnya seperti ini :