Nama: Ayu Mutiara Sari
NRP: 05111740000149
Kelas: PWEB C
Link (masih dalam proses) :still on process
1. Database:
2. Interface
3. Source Code:
- awal.php
- cek_login.php
- daftar.php
- download.php
- errors.php
- form-daftar.php
- form-edit.php
- hapus.php
- index.php
- koneksi.php
- list-siswa.php
- login.php
- proses-edit.php
- proses-pendaftaran.php
- style.css
-view.php
NRP: 05111740000149
Kelas: PWEB C
Link (masih dalam proses) :still on process
1. Database:
2. Interface
3. Source Code:
- awal.php
<!DOCTYPE html>
<html>
<head>
</head>
<style type="text/css">
ul{
display:table; margin:0 auto;
}
body {
background-color: LightPink;
}
</style>
<body>
<header>
<h1 align="center">Pendaftaran Siswa Baru Kabupaten Sukamaju</h3>
<h3 align="center">Tingkat Sekolah Menengah Atas</h1>
</header>
<h4 align="center">Menu</h4>
<nav>
<ul>
<li><a href="form-daftar.php">Isi Formulir</a></li>
<li><a href="list-siswa.php">Edit/Hapus</a></li>
<li><a href="view.php">Lihat Formulir</a></li>
</ul>
</nav>
</body>
</html>
- cek_login.php
<?php
session_start();
// initializing variables
$username = "";
$email = "";
$errors = array();
// connect to the database
$db = mysqli_connect('localhost', 'root', '', 'ppdb');
// REGISTER USER
if (isset($_POST['daftar'])) {
// receive all input values from the form
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password1 = mysqli_real_escape_string($db, $_POST['password1']);
$password2 = mysqli_real_escape_string($db, $_POST['password2']);
// 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($password1)) { array_push($errors, "Password is required"); }
if ($password1 != $password2) {
array_push($errors, "The two passwords do not match");
}
$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['username'] === $username) {
array_push($errors, "Username already exists");
}
if ($user['email'] === $email) {
array_push($errors, "email already exists");
}
}
if (count($errors) == 0) {
$password = md5($password1);
$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');
}
}
// ...
if (isset($_POST['submit'])) {
$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");
}
}
}
?>
- daftar.php
<?php include('cek_login.php') ?>
<!DOCTYPE html>
<html>
<head>
<title>Formulir Pendaftaran Siswa Baru 2019 Kabupaten Sukamaju</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<h2>Register</h2>
</div>
<form method="post" action="daftar.php">
<?php include('errors.php'); ?>
<div class="input-group">
<label>Username</label>
<input type="text" name="username" value="<?php echo $username; ?>">
</div>
<div class="input-group">
<label>Email</label>
<input type="email" name="email" value="<?php echo $email; ?>">
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password1">
</div>
<div class="input-group">
<label>Confirm password</label>
<input type="password" name="password2">
</div>
<div class="input-group">
<button type="submit" class="btn" name="daftar">Register</button>
</div>
<p>
Already a member? <a href="login.php">Sign in</a>
</p>
</form>
</body>
</html>
- download.php
<?php
//export.php
$connect = mysqli_connect("localhost", "root", "", "ppdb");
$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>nik</th>
<th>nama</th>
<th>tempat_lahir</th>
<th>tanggal_lahir</th>
<th>alamat</th>
<th>jenis_kelamin</th>
<th>agama</th>
<th>sekolah_asal</th>
<th>pilihan1</th>
<th>pilihan2</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["id"].'</td>
<td>'.$row["nik"].'</td>
<td>'.$row["nama"].'</td>
<td>'.$row["tempat_lahir"].'</td>
<td>'.$row["tanggal_lahir"].'</td>
<td>'.$row["alamat"].'</td>
<td>'.$row["jenis_kelamin"].'</td>
<td>'.$row["agama"].'</td>
<td>'.$row["sekolah_asal"].'</td>
<td>'.$row["pilihan1"].'</td>
<td>'.$row["pilihan2"].'</td>
</tr>
';
}
$output .= '</table>';
header('Content-Type: application/xls');
header('Content-Disposition: attachment; filename=download.xls');
echo $output;
}
}
?>
- errors.php
<?php if (count($errors) > 0) : ?>
<div class="error">
<?php foreach ($errors as $error) : ?>
<p><?php echo $error ?></p>
<?php endforeach ?>
</div>
<?php endif ?>
- form-daftar.php
<!DOCTYPE html>
<html>
<head>
<title>Formulir Pendaftaran Siswa Kabupaten Sukamaju</title>
<style type="text/css">
body {
background-color: LightPink;
}
fieldset{
background-color: #FFF0F5;
}
</style>
</head>
<body>
<header>
<h3>Formulir Pendaftaran Siswa Baru</h3>
</header>
<form action="proses-pendaftaran.php" method="POST">
<fieldset>
<p>
<label for="nik">NIK: </label>
<input type="text" name="nik" placeholder="NIK" />
</p> `
<p>
<label for="nama">Nama: </label>
<input type="text" name="nama" placeholder="nama lengkap" />
</p>
<p>
<label for="tempat_lahir">Tempat Lahir: </label>
<input type="text" name="tempat_lahir" placeholder="tempat lahir" />
</p>
<p>
<label for="tanggal_lahir">Tanggal Lahir(dd/mm/yyyy): </label>
<input type="text" name="tanggal_lahir" placeholder="tanggal_lahir" />
</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 Sukamaju</option>
<option>SMA 2 Sukamaju</option>
<option>SMA 3 Sukamaju</option>
<option>SMA 4 Sukamaju</option>
<option>SMA 5 Sukamaju</option>
</select>
</p>
<p>
<label for="pilihan2">Pilihan 2: </label>
<select name="pilihan2">
<option>SMA 1 Sukamaju</option>
<option>SMA 2 Sukamaju</option>
<option>SMA 3 Sukamaju</option>
<option>SMA 4 Sukamaju</option>
<option>SMA 5 Sukamaju</option>
</select>
</p>
<p>
<input type="submit" value="Daftar" name="daftar" />
</p>
</fieldset>
</form>
</body>
</html>
- form-edit.php
<?php
include("koneksi.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 Pendaftaran Siswa Kabupaten Sukamaju</title>
<style type="text/css">
body {
background-color: LightPink;
}
fieldset{
background-color: #FFF0F5;
}
</style>
</head>
<body>
<header>
<h3>Formulir Pendaftaran Siswa Baru</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="tempat_lahir">Tempat Lahir: </label>
<input type="text" name="tempat_lahir" placeholder="tempat lahir" value="<?php echo $siswa['tempat_lahir'] ?>"/>
</p>
<p>
<label for="tanggal_lahir">Tanggal Lahir(dd/mm/yyyy): </label>
<input type="text" name="tanggal_lahir" placeholder="tanggal_lahir" value="<?php echo $siswa['tanggal_lahir'] ?>"/>
</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 Sukamaju</option>
<option>SMA 2 Sukamaju</option>
<option>SMA 3 Sukamaju</option>
<option>SMA 4 Sukamaju</option>
<option>SMA 5 Sukamaju</option>
</select>
</p>
<p>
<label for="pilihan2">Pilihan 2: </label>
<select name="pilihan2">
<option>SMA 1 Sukamaju</option>
<option>SMA 2 Sukamaju</option>
<option>SMA 3 Sukamaju</option>
<option>SMA 4 Sukamaju</option>
<option>SMA 5 Sukamaju</option>
</select>
</p>
<p>
<p>
<input type="submit" value="Simpan" name="simpan" />
</p>
</fieldset>
</form>
</body>
</html>
- hapus.php
<?php
include("koneksi.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...");
}
?>
- 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>
<title>Home</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">
<h2>Home Page</h2>
</div>
<div class="content">
<!-- notification message -->
<?php if (isset($_SESSION['success'])) : ?>
<div class="error success" >
<h3>
<?php
echo $_SESSION['success'];
unset($_SESSION['success']);
?>
</h3>
</div>
<?php endif ?>
<!-- logged in user information -->
<?php if (isset($_SESSION['username'])) : ?>
<p>Welcome <strong><?php echo $_SESSION['username']; ?></strong></p>
<p> <a href="awal.php" style="color: red;">Fill The Formulir</a> </p>
<p> <a href="index.php?logout='1'" style="color: red;">Logout</a> </p>
<?php endif ?>
</div>
</body>
</html>
- koneksi.php
<?php
$server = "localhost";
$user = "root";
$password = "";
$nama_database = "ppdb";
$db = mysqli_connect($server, $user, $password , $nama_database);
if( !$db ){
die("Gagal terhubung dengan database: " . mysqli_connect_error());
}
?>
- list-siswa.php
<?php include("koneksi.php"); ?>
<!DOCTYPE html>
<html>
<head>
<title>Formulir Pendaftaran Siswa Baru Kabupaten Sukamaju</title>
<style type="text/css">
body {
background-color: LightPink;
}
fieldset{
background-color: #FFF0F5;
}
</style>
</head>
</style>
<body>
<header>
<h2 align="center">FORMULIR PENDAFTARAN SISWA BARU KABUPATEN SUKAMAJU</h2>
<h3 align="center">TINGKAT SEKOLAH MENENGAH ATAS</h3>
</header>
<fieldset>
<p>
<?php
$sql = "SELECT * FROM calon_siswa";
$query = mysqli_query($db, $sql);
$siswa = mysqli_fetch_array($query);
echo "<p align='center'> FORMULIR PENDAFTARAN SISWA BARU KABUPATEN SUKAMAJU</p>";
echo " <p align='center'> SEKOLAH MENENGAH ATAS </p>";
echo "<br />";
echo "<br />";
echo "<strong>ID</strong><br>";
echo $siswa['id']; echo "<br>";
echo "<br />";
echo "<strong>NIK</strong><br>";
echo $siswa['nik']; echo "<br>";
echo "<br />";
echo "<strong>Nama</strong><br>";
echo $siswa['nama']; echo "<br>";
echo "<br />";
echo "<strong>Tempat Lahir</strong><br>";
echo $siswa['tempat_lahir']; echo "<br>";
echo "<br />";
echo "<strong>Tanggal Lahir</strong><br>";
echo $siswa['tanggal_lahir']; echo "<br>";
echo "<br />";
echo "<strong>Alamat</strong><br>";
echo $siswa['alamat']; echo "<br>";
echo "<br />";
echo "<strong>Jenis Kelamin</strong><br>";
echo $siswa['jenis_kelamin']; echo "<br>";
echo "<br />";
echo "<strong>Agama</strong><br>";
echo $siswa['agama']; echo "<br>";
echo "<br />";
echo "<strong>Sekolah Asal</strong><br>";
echo $siswa['sekolah_asal']; echo "<br>";
echo "<br />";
echo "<strong>Sekolah Pilihan 1</strong><br>";
echo $siswa['pilihan1']; echo "<br>";
echo "<strong>Sekolah Pilihan 2</strong><br>";
echo $siswa['pilihan2']; echo "<br>";
echo "<br /></br>";
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>";
?>
</p>
</html>
</body>
- login.php
<?php
include "koneksi.php";
session_start();
if (isset($_SESSION['username'])){
header ("location:index.php");
}
?>
<html>
<head>
<title>PENDAFTARAN SISWA BARU KABUPATEN SUKAMAJU</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 Baru Kabupaten Sukamaju</h1>
<div class="header">
<td colspan=3><center><font size=5>LOGIN</font></center></td>
</div>
</tr>
<tr>
<td>Username</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="LOGIN"></td>
</tr>
<tr>
<td> Belum Mendaftar? Klik </td>
<td colspan=3><a href="daftar.php">DAFTAR</a></td>
</tr>
</table>
</form>
</body>
</html>
- proses-edit.php
<?php
include("koneksi.php");
// cek apakah tombol simpan sudah diklik atau blum?
if(isset($_POST['simpan'])){
// ambil data dari formulir
$id = $_POST['id'];
$nik = $_POST['nik'];
$nama = $_POST['nama'];
$tempat_lahir = $_POST['tempat_lahir'];
$tanggal_lahir = $_POST['tanggal_lahir'];
$alamat = $_POST['alamat'];
$jk = $_POST['jenis_kelamin'];
$agama = $_POST['agama'];
$sekolah = $_POST['sekolah_asal'];
$pilihan1 = $_POST['pilihan1'];
$pilihan2 = $_POST['pilihan2'];
// buat query update
$sql = "UPDATE calon_siswa SET nik='$nik',nama='$nama', tempat_lahir='$tempat_lahir', tanggal_lahir='$tanggal_lahir', alamat='$alamat', jenis_kelamin='$jk', agama='$agama', sekolah_asal='$sekolah', pilihan1='$pilihan1', pilihan2='$pilihan2' 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
<?php
include("koneksi.php");
// cek apakah tombol daftar sudah diklik atau blum?
if(isset($_POST['daftar'])){
// ambil data dari formulir
$nik = $_POST['nik'];
$nama = $_POST['nama'];
$tempat_lahir = $_POST['tempat_lahir'];
$tanggal_lahir = $_POST['tanggal_lahir'];
$alamat = $_POST['alamat'];
$jk = $_POST['jenis_kelamin'];
$agama = $_POST['agama'];
$sekolah = $_POST['sekolah_asal'];
$pilihan1 = $_POST['pilihan1'];
$pilihan2 = $_POST['pilihan2'];
// buat query
$sql = "INSERT INTO calon_siswa (nik, nama, tempat_lahir, tanggal_lahir, alamat, jenis_kelamin, agama, sekolah_asal, pilihan1, pilihan2) VALUE ('$nik', '$nama', '$tempat_lahir', '$tanggal_lahir', '$alamat', '$jk', '$agama', '$sekolah', '$pilihan1', '$pilihan2')";
$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...");
}
?>
- style.css
* {
margin: 1px;
padding: 1px;
}
body {
font-size: 120%;
background:#FFB6C1;
}
.header {
width: 20%;
margin: 50px auto 0px;
color: black;
background: #FFF8DC;
text-align: center;
border: 1px solid #B0C4DE;
border-bottom: none;
border-radius: 10px 10px 0px 0px;
padding: 20px;
}
form, .content {
width: 30%;
margin: 0px auto;
padding: 20px;
border: 1px solid #FFF8DC;
background: white;
border-radius: 0px 0px 10px 10px;
}
.input-group {
margin: 10px 0px 10px 0px;
}
.input-group label {
display: block;
text-align: left;
margin: 3px;
}
.input-group input {
height: 30px;
width: 93%;
padding: 5px 10px;
font-size: 16px;
border-radius: 5px;
border: 1px solid gray;
}
.btn {
padding: 10px;
font-size: 15px;
color: black;
background: #FFF8DC;
border: none;
border-radius: 5px;
}
.error {
width: 92%;
margin: 0px auto;
padding: 10px;
border: 1px solid #FFF8DC;
color: #a94442;
background: #f2dede;
border-radius: 5px;
text-align: left;
}
}
-view.php
<?php include("koneksi.php"); ?>
<!DOCTYPE html>
<html>
<head>
<title>Formulir Pendaftaran Siswa Baru Kabupaten Sukamaju</title>
<style type="text/css">
body {
background-color: LightPink;
}
fieldset{
background-color: #FFF0F5;
}
</style>
</head>
</style>
<body>
<header>
<h2 align="center">FORMULIR PENDAFTARAN SISWA BARU KABUPATEN SUKAMAJU</h2>
<h3 align="center">SEKOLAH MENENGAH ATAS</h3>
</header>
<div class="login">
<fieldset>
<p>
<?php
$sql = "SELECT * FROM calon_siswa";
$query = mysqli_query($db, $sql);
$siswa = mysqli_fetch_array($query);
echo "<p align='center'> FORMULIR PENDAFTARAN SISWA BARU 2019 KABUPATEN SUKAMAJU</p>";
echo " <p align='center'> SEKOLAH MENENGAH ATAS</p>";
echo "<br />";
echo "<br />";
echo "<strong>ID</strong><br>";
echo $siswa['id']; echo "<br>";
echo "<strong>NIK</strong><br>";
echo $siswa['nik']; echo "<br>";
echo "<br />";
echo "<strong>Nama</strong><br>";
echo $siswa['nama']; echo "<br>";
echo "<br />";
echo "<strong>Tempat Lahir</strong><br>";
echo $siswa['tempat_lahir']; echo "<br>";
echo "<br />";
echo "<strong>Tanggal Lahir</strong><br>";
echo $siswa['tanggal_lahir']; echo "<br>";
echo "<br />";
echo "<strong>Alamat</strong><br>";
echo $siswa['alamat']; echo "<br>";
echo "<br />";
echo "<strong>Jenis Kelamin</strong><br>";
echo $siswa['jenis_kelamin']; echo "<br>";
echo "<br />";
echo "<strong>Agama</strong><br>";
echo $siswa['agama']; echo "<br>";
echo "<br />";
echo "<strong>Sekolah Asal</strong><br>";
echo $siswa['sekolah_asal']; echo "<br>";
echo "<br />";
echo "<strong>Sekolah Pilihan 1</strong><br>";
echo $siswa['pilihan1']; echo "<br>";
echo "<br />";
echo "<strong>Sekolah Pilihan 2</strong><br>";
echo $siswa['pilihan2']; echo "<br>";
?>
</p>
<form method="post" action="download.php">
<input type="submit" name="download" class="btn btn-success" value="Download" />
</html>
</body>