PWEB C - EAS MEMBUAT PPDB ONLINE
1. Rancangan Interface
2. Rancangan Database
a. table calon_siswa
b. table users
3. Implementasi
Source code :
1. cek_login.php
<?php
ob_start();
include "koneksi.php";
$username = $_POST['username'];
$password = $_POST['password'];
if (empty($username)){
echo "<script>alert('Username belum diisi')</script>";
echo "<meta http-equiv='refresh' content='1 url=index.php'>";
}else if (empty($password)){
echo "<script>alert('Password belum diisi')</script>";
echo "<meta http-equiv='refresh' content='1 url=index.php'>";
}else{
session_start();
$login = " SELECT * from users WHERE username='$username' AND password1='$password'";
$query = mysqli_query($db, $login);
$row =mysqli_num_rows($query);
if ( $row > 0){
$_SESSION['username']=$username;
header('Location:menu.php');
ob_end_flush();
}
else{
echo "<script>alert('Username atau Password salah')</script>";
echo "<meta http-equiv='refresh' content='1 url=index.php'>";
}
}
?>
2. Daftar.php
<html>
<head>
<title>Pendaftaran</title>
</head>
<body>
<form method="post" name="pendaftaran" action="cek_daftar.php">
<table border=0 align="center" cellpadding=5 cellspacing=0>
<tr>
<td colspan=3><center><font size=5>PENDAFTARAN</font></center></td>
</tr>
<tr>
<td>Email</td><td>:</td><td><input type="text" name="email"></td>
</tr>
<tr>
<td>NISN</td><td>:</td><td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td><td>:</td><td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan=2> </td>
<td><input type="submit" name="submit" value="DAFTAR"></td>
</tr>
<tr>
<td colspan=3><a href="index.php">LOGIN</a></td>
</tr>
</table>
</form>
</body>
</html>
3. Download.php
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
//export.php
$connect = mysqli_connect("localhost", "id8215339_nandha", "nandha", "id8215339_nandha");
$output = '';
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: index.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['username']);
header("location: xml_get_current_byte_index(parser).php");
}
$userid = $_SESSION['username'];
if(isset($_POST["download"]))
{
$query = "SELECT * FROM calon_siswa WHERE NISN = $userid";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '
<table class="table" bordered="1">
<tr>
<th>id</th>
<th>NISN</th>
<th>nama</th>
<th>alamat</th>
<th>jenis_kelamin</th>
<th>agama</th>
<th>sekolah_asal</th>
<th>pilihan1</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["id"].'</td>
<td>'.$row["NISN"].'</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["pilihan1"].'</td>
</tr>
';
}
$output .= '</table>';
header('Content-Type: application/xls');
header('Content-Disposition: attachment; filename=download.xls');
echo $output;
}
}
?>
4. Cek_daftar.php
<?php include "koneksi.php"; $email = $_POST['email']; $username = $_POST['username']; $password = $_POST['password']; if (empty($email)){ echo "<script>alert('Email belum diisi')</script>"; echo "<meta http-equiv='refresh' content='1 url=daftar.php'>"; }else if(empty($username)){ echo "<script>alert('Username belum diisi')</script>"; echo "<meta http-equiv='refresh' content='1 url=daftar.php'>"; }else if (empty($password)){ echo "<script>alert('Password belum diisi')</script>"; echo "<meta http-equiv='refresh' content='1 url=daftar.php'>"; }else{$daftar = "INSERT INTO users (email,username,password1) values ('$email','$username','$password')"; $query = mysqli_query($db, $daftar); if ($query){ echo "<script>alert('Berhasil Mendaftar')</script>"; echo "<meta http-equiv='refresh' content='1 url=index.php'>"; }else{ echo "<script>alert('Gagal Mendaftar')</script>"; echo "<meta http-equiv='refresh' content='1 url=daftar.php'>"; } } ?>
5. Formdaftar.php
<?php
session_start();
if (!isset($_SESSION['username'])) {
$_SESSION['msg'] = "You must log in first";
header('location: index.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['username']);
header("location: xml_get_current_byte_index(parser).php");
}
?><!DOCTYPE html>
<html>
<head>
<title>Formulir Pendaftaran Siswa Kabupaten TC</title>
<style type="text/css">
body {
background-color: LightGray;
}
fieldset{
background-color: Gray;
}
</style>
</head>
<body>
<header>
<h3>Formulir Pendaftaran Siswa Baru</h3>
</header>
<form action="prosesdaftar.php" method="POST">
<fieldset>
<p>
<label for="NISN">NISN: </label>
<input type="text" name="NISN" value="<?php echo $_SESSION['username'] ?>" />
</p>
<p>
<label for="nama">Nama: </label>
<input type="text" name="nama" placeholder="nama" />
</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>Katolik</option>
</select>
</p>
<p>
<label for="sekolah_asal">Sekolah Asal: </label>
<input type="text" name="sekolah_asal" placeholder="nama sekolah" />
</p>
<p>
<label for="pilihan1">Pilihan 1: </label>
<select name="pilihan1">
<option>SMA 1 TC</option>
<option>SMA 2 TC</option>
<option>SMA 3 TC</option>
<option>SMA 4 TC</option>
<option>SMA 5 TC</option>
</select>
</p>
<p>
<input type="submit" value="Daftar" name="daftar" />
</p>
</fieldset>
</form>
</body>
</html>
6. Formedit.php
<?php include("koneksi.php"); // kalau tidak ada id di query string if( !isset($_GET['id']) ){ header('Location: list.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 Pendaftaran Siswa Kabupaten TC</title> <style type="text/css"> body { background-color: LightGray; } fieldset{ background-color: Gray; } </style> </head> <body> <header> <h3>Formulir Pendaftaran Siswa Baru</h3> </header> <form action="prosesedit.php" method="POST"> <fieldset> <input type="hidden" name="id" value="<?php echo $siswa['id'] ?>" /> <p> <label for="nama">NISN: </label> <input type="text" name="NISN" value="<?php echo $siswa['NISN'] ?>" /> </p> <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 == 'Katolik') ? "selected": "" ?>>Katolik</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> <label for="pilihan1">Pilihan 1: </label> <select name="pilihan1"> <option>SMA 1 TC</option> <option>SMA 2 TC</option> <option>SMA 3 TC</option> <option>SMA 4 TC</option> <option>SMA 5 TC</option> </select> </p> <p> <input type="submit" value="Simpan" name="simpan" /> </p> </fieldset> </form> </body> </html>
7. Index.php
<?php
include ('koneksi.php');
?>
<html>
<head>
<title>PENDAFTARAN SISWA SMA KABUPATEN TC</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body style="text-align: center;">
<form method="post" name="login" action="cek_login.php">
<table border=0 align="center" cellpadding=5 cellspacing=0>
<tr>
<h1>Pendaftaran Siswa Kabupaten TC</h1>
<div class="header">
<td colspan=3><center><font size=5>LOGIN</font></center></td>
</div>
</tr>
<tr>
<td>NISN</td>
<td>:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan=2></td>
<td><input type="submit" name="login" value="LOGIN"></td>
</tr>
<tr>
<td colspan=3><a href="daftar.php">DAFTAR</a></td>
</tr>
</table>
</form>
</body>
</html>
8. Koneksi.php
<?php
$server = "localhost";
$user = "id8215339_nandha";
$password = "nandha";
$nama_database = "id8215339_nandha";
$db = mysqli_connect($server, $user, $password , $nama_database);
if( !$db ){
die("Gagal terhubung dengan database: " . mysqli_connect_error());
}
?>
9. Menu.php
<?php session_start(); if (!isset($_SESSION['username'])) { $_SESSION['msg'] = "You must log in first"; header('location: index.php'); } if (isset($_GET['logout'])) { session_destroy(); unset($_SESSION['username']); header("location: xml_get_current_byte_index(parser).php"); } ?> <!DOCTYPE html> <html> <head> </head> <style type="text/css"> ul{ display:table; margin:0 auto; } body { background-color: LightGray; } </style> <body> <header> <h1 align="center">Pendaftaran Siswa Baru Kabupaten TC</h1> </header> <h3 align="center">Menu</h3> <?php if (isset($_SESSION['username'])) : ?> <h3 align="center"> Welcome <?php echo $_SESSION['username']?> </h3> <nav> <ul> <li><a href="formdaftar.php">Isi Formulir</a></li> <br> <li><a href="list.php">Lihat Formulir</a></li> <br> <p> <a href="logout.php" style="color: BLUE">Logout</a> </p> <?php endif ?> </ul> </nav> </div>
</body> </html>
10. Prosesdaftar.php
<?php
ob_start();
include("koneksi.php");
if(isset($_POST['daftar'])){
$NISN = $_POST['NISN'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$jk = $_POST['jenis_kelamin'];
$agama = $_POST['agama'];
$sekolah = $_POST['sekolah_asal'];
$pilihan1 = $_POST['pilihan1'];
$sql = "INSERT INTO calon_siswa (NISN, nama, alamat, jenis_kelamin, agama, sekolah_asal, pilihan1) VALUE ('$NISN', '$nama', '$alamat', '$jk', '$agama', '$sekolah', '$pilihan1')";
$query = mysqli_query($db, $sql);
if( $query ) {
header('Location: list.php');
ob_end_flush();
} else {
echo "Gagal daftar.";
}
} else {
die("Akses dilarang...");
}
?>
11. Prosesedit.php
<?php
include("koneksi.php");
if(isset($_POST['simpan'])){
$id = $_POST['id'];
$NISN = $_POST['NISN'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$jk = $_POST['jenis_kelamin'];
$agama = $_POST['agama'];
$sekolah = $_POST['sekolah_asal'];
$pilihan1 = $_POST['pilihan1'];
$sql = "UPDATE calon_siswa SET NISN='$NISN',nama='$nama', alamat='$alamat', jenis_kelamin='$jk', agama='$agama', sekolah_asal='$sekolah', pilihan1='$pilihan1' WHERE id=$id";
$query = mysqli_query($db, $sql);
if( $query ) {
header('Location: list.php');
} else {
die("Gagal menyimpan perubahan...");
}
} else {
die("Akses dilarang...");
}
?>
12. List.php
<?php include("koneksi.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: xml_get_current_byte_index(parser).php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Formulir Pendaftaran Siswa Kabupaten TC</title>
</head>
</style>
<body bgcolor="#E6E6FA">
<header>
<h2 align="center">Formulir Pendaftaran Siswa Baru</h2>
</header>
<fieldset>
<p>
<?php
$userid = $_SESSION['username'];
$sql = "SELECT * FROM calon_siswa WHERE NISN = '$userid' ";
$query = mysqli_query($db, $sql);
$siswa = mysqli_fetch_array($query);
echo "<br />";
echo "<br />";
echo "NISN : ";
echo $siswa['NISN']; echo "<br>";
echo "Nama : ";
echo $siswa['nama']; echo "<br>";
echo "Alamat : ";
echo $siswa['alamat']; echo "<br>";
echo "Jenis Kelamin : ";
echo $siswa['jenis_kelamin']; echo "<br>";
echo "Agama : ";
echo $siswa['agama']; echo "<br>";
echo "Sekolah Asal : ";
echo $siswa['sekolah_asal']; echo "<br>";
echo "Sekolah Pilihan : ";
echo $siswa['pilihan1']; echo "<br>";
echo "<br /></br>";
echo "<td>";
echo "<a href='formedit.php?id=".$siswa['id']."'>Edit | </a> ";
echo "<a href='menu.php?id=".$siswa['id']."'>Home</a> ";
?>
<form method="post" action="download.php">
<input type="submit" name="download" class="btn btn-success" value="Download" />
</p>
</html>
</body>
13. Logout.php
<?php
session_start();
session_destroy();
?>
<div align="center">
<h2>Anda telah berhasil logout..</h2>
Silahkan klik <a href="index.php">disini</a> untuk login kembali
</div>
TAMPILAN :
1. Tampilan awal berupa halaman login
2. Tampilan halaman register
3. Tampilan halaman setelah login
4. Mengisi formulir
5. Menampilkan formulir
6, Edit formulir
7, Download
8. Logout
9. File yang di download
Komentar
Posting Komentar