Nama : Bobbi Aditya
NRP : 05111740000099
Kelas : PWEB C
Dalam pengerjaan tugas ini, saya tidak menggunakan framework apa-apa. Pada awalnya, saya mencoba menggunakan framework dalam proses pengerjaan ujian ini. Tetapi pada pertengahan proses pembuatan, saya mengalami kesusahan dalam menyelesaikannya. Oleh karena itu, karena keterbatasan waktu juga, saya memutuskan untuk menyelesaikan tugas ini tanpa menggunakan framework
Dalam rancangan database saya, saya membuat 2 buah tabel.
Tabel pertama berguna untuk menyimpan data user yang nantinya dibutuhkan pada saat login. Di dalam tabel pertama ini terdapat 3 buah atribut. Rancangannya adalah sebagai berikut:
Tabel kedua berguna untuk menyimpan data siswa, rancangan dari tabel kedua adalah sebagai berikut
Untuk rancangan interfacesnya saya berencana untuk membedakan tampilan login awal, dengan tampilan sesudah login.
Setelah login, maka tampilannya akan berubah menjadi seperti ini::
Hasil dari pekerjaan saya bisa diakses di link ini
Berikut adalah kodingan dari maisng-masing page yang saya buat:
-config.php
<?php
$server = "localhost";
$user = "rumahbun_bobbi";
$password = "bobbibobbibobbi";
$nama_database = "rumahbun_ppdb";
$db = mysqli_connect($server, $user, $password, $nama_database);
// echo "Berhasil bossku";
if( !$db ){
die("Gagal terhubung dengan database: " . mysqli_connect_error());
}
?>
-download.php
<?php
$connect = mysqli_connect("localhost", "rumahbun_bobbi", "bobbibobbibobbi", "rumahbun_ppdb");
$sql = "SELECT * FROM siswa";
$result = mysqli_query($connect, $sql);
?>
<html>
<head>
<title>Download Hasil data</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<div class="container">
<br />
<br />
<br />
<div class="table-responsive">
<h2 align="center">FORMULIR PPDB </h2><br />
<table class="table table-bordered">
<tr>
<th>Nama Lengkap</th>
<th>NISN</th>
<th>NIK</th>
<th>Jenjang</th>
<th>Sekolah_asal</th>
<th>Agama</th>
<th>Tempat Lahir</th>
<th>tgl_lahir</th>
<th>Jenis_Kelamin</th>
<th>Alamat</th>
<th>Sekolah_Tujuan</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
echo '
<tr>
<td>'.$row["nama_lengkap"].'</td>
<td>'.$row["NISN"].'</td>
<td>'.$row["NIK"].'</td>
<td>'.$row["jenjang"].'</td>
<td>'.$row["sekolah_asal"].'</td>
<td>'.$row["agama"].'</td>
<td>'.$row["tmpt_lahir"].'</td>
<td>'.$row["tgl_lahir"].'</td>
<td>'.$row["jenis_kel"].'</td>
<td>'.$row["alamat"].'</td>
<td>'.$row["sekolah_tujuan"].'</td>
</tr>
';
}
?>
</table>
<br />
<form method="post" action="export.php">
<input type="submit" name="export" class="btn btn-success" value="Export" />
</form>
</div>
</div>
</body>
</html>
-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 ?>
-export.php
<?php
//export.php
$connect = mysqli_connect("localhost", "rumahbun_bobbi", "bobbibobbibobbi", "rumahbun_ppdb");
$output = '';
if(isset($_POST["export"]))
{
$query = "SELECT * FROM siswa";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '
<table class="table" bordered="1">
<tr>
<th>Nama Lengkap</th>
<th>NISN</th>
<th>NIK</th>
<th>Jenjang</th>
<th>Sekolah_asal</th>
<th>Agama</th>
<th>Tempat Lahir</th>
<th>tgl_lahir</th>
<th>Jenis_Kelamin</th>
<th>Alamat</th>
<th>Sekolah_Tujuan</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["nama_lengkap"].'</td>
<td>'.$row["NISN"].'</td>
<td>'.$row["NIK"].'</td>
<td>'.$row["jenjang"].'</td>
<td>'.$row["sekolah_asal"].'</td>
<td>'.$row["agama"].'</td>
<td>'.$row["tmpt_lahir"].'</td>
<td>'.$row["tgl_lahir"].'</td>
<td>'.$row["jenis_kel"].'</td>
<td>'.$row["alamat"].'</td>
<td>'.$row["sekolah_tujuan"].'</td>
</tr>
';
}
$output .= '</table>';
header('Content-Type: application/xls');
header('Content-Disposition: attachment; filename=download.xls');
echo $output;
}
}
?>
-form-edit.php
<?php
include("config.php");
// kalau tidak ada id di query string
if( !isset($_GET['id']) ){
header('Location: view.php');
}
//ambil id dari query string
$id = $_GET['id'];
// buat query untuk ambil data dari database
$sql = "SELECT * FROM siswa WHERE siswa_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>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Pendaftaran siswa online|</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top">
<div class="container">
<a class="navbar-brand" href="index.php">Pendaftaran Siswa Online</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="index.php?logout='1'">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<form action="proses-edit.php" method="post" style="width: 720px;position: absolute;left: 25%;" >
<input type="hidden" name="siswa_id" value="<?php echo $siswa['siswa_id'] ?>" />
<div class="form-group">
<label for="NISN">NISN</label>
<input class="form-control type="text" name="NISN" value="<?php echo $siswa['NISN'] ?>" />
</div>
<div class="form-group">
<label for="NIK">NIK</label>
<input class="form-control type="text" name="NIK" value="<?php echo $siswa['NIK'] ?>" />
</div>
<div class="form-group">
<label for="nama_lengkap">Nama Lengkap</label>
<input class="form-control type="text" name="nama_lengkap" value="<?php echo $siswa['nama_lengkap'] ?>" />
</div>
</div>
<div class="form-group">
<label for="jenjang">Jenjang: </label>
<?php $jenjang = $siswa['jenjang']; ?>
<select class="form-control" name="jenjang">
<option <?php echo ($jenjang=='SD') ?>>SD</option>
<option <?php echo ($jenjang=='SMP') ?>>SMP</option>
</select>
</div>
<div class="form-group">
<label for="sekolah_asal">Sekolah Asal</label>
<input class="form-control type="text" name="sekolah_asal" value="<?php echo $siswa['sekolah_asal'] ?>" />
</div>
<div class="form-group">
<label for="agama">Agama: </label>
<?php $agama = $siswa['agama']; ?>
<select class="form-control" 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>
</div>
<div class="form-group">
<label for="tmpt_lahir">Tempat Lahir</label>
<input class="form-control type="text" name="tmpt_lahir" value="<?php echo $siswa['tmpt_lahir'] ?>" />
</div>
<div class="form-group">
<label for="tgl_lahir">Tanggal Lahir</label>
<input class="form-control type="text" name="tgl_lahir" value="<?php echo $siswa['tgl_lahir'] ?>" />
</div>
<div class="form-group">
<label for="jenis_kel">Jenis Kelamin: </label>
<?php $jk = $siswa['jenis_kel']; ?>
<br>
<label><input type="radio" name="jenis_kel" value="pria" <?php echo ($jk == 'pria') ? "checked": "" ?>> Laki-laki</label>
<br>
<label><input type="radio" name="jenis_kel" value="wanita" <?php echo ($jk == 'wanita') ? "checked": "" ?>> Perempuan</label>
</div>
<div class="form-group">
<label for="alamat">Alamat: </label>
<textarea class="form-control" name="alamat"><?php echo $siswa['alamat'] ?></textarea>
</div>
<div class="form-group">
<label for="sekolah_tujuan">Sekolah Tujuan</label>
<input class="form-control type="text" name="sekolah_tujuan" value="<?php echo $siswa['sekolah_tujuan'] ?>" />
</div>
<input type="submit" class="btn btn-success" value="Simpan" name="simpan" />
</div>
</form>
<br>
<br>
</body>
-hapus.php
<?php
include("config.php");
if( isset($_GET['id']) ){
// ambil id dari query string
$id = $_GET['id'];
// buat query hapus
$sql = "DELETE FROM siswa WHERE siswa_id=$id";
$query = mysqli_query($db, $sql);
// apakah query hapus berhasil?
if( $query ){
header('Location: view.php');
} else {
die("gagal menghapus...");
}
} else {
die("akses dilarang...");
}
?>
-index.php
<?php include('server.php') ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Pendaftaran siswa online|</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top">
<div class="container">
<a class="navbar-brand" href="index.php">Pendaftaran Siswa Online</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="login.php">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="register.php">Register</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Page Content -->
<div class='container' style='margin-top: 100px;'>
<div class='row'>
<div class='col-md-4'>
</div>
<div class='col-md-4'>
<div class='panel panel-default'>
<div class='panel-body'>
<form method="post" action="index.php">
<div class="form-group">
<label for="NISN">NISN</label>
<input type="text" class="form-control" name="NISN" id="NISN" placeholder="NISN">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password" id="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary" name="login_user">LOGIN</button>
<a href="register.php" class="btn btn-link">Sign Up</a>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
-index2.php
<?php
session_start();
if (!isset($_SESSION['NISN'])) {
$_SESSION['msg'] = "You must log in first";
header('location: index.php');
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['NISN']);
header("location: xml_get_current_byte_index(parser).php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Pendaftaran siswa online|</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top">
<div class="container">
<a class="navbar-brand" href="index.php">Pendaftaran Siswa Online</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="index.php?logout='1'">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- 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['NISN'])) : ?>
<div class="container bg-light" style="text-align: center;">
<h1>Welcome <kbd><?php echo $_SESSION['NISN']; ?></kbd></h1>
<div>
<a href="input_data.php" type="button" class="btn btn-primary bg-dark"> <h3>Isi Data</h3></a>
</div>
<br>
<br>
<div>
<a href="view.php" type="button" class="btn btn-primary bg-dark"> <h3>View Data</h3></a>
</div>
<br>
<br>
<div>
<a href="download.php" type="button" class="btn btn-primary bg-dark"> <h3>Download Data</h3></a>
</div>
</div>
<?php endif ?>
</div>
</body>
</html>
-input_data.php
<!DOCTYPE HTML>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Pendaftaran siswa online|</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top">
<div class="container">
<a class="navbar-brand" href="index.php">Pendaftaran Siswa Online</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="index.php?logout='1'">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<form action="proses-pendaftaran.php" method="post" style="width: 720px;position: absolute;left: 25%;" >
<div class="form-group">
<label for="NISN">NISN</label>
<input class="form-control type="text" name="NISN" placeholder="NISN" />
</div>
<div class="form-group">
<label for="NIK">NIK</label>
<input class="form-control type="text" name="NIK" placeholder="NIK" />
</div>
<div class="form-group">
<label for="nama_lengkap">Nama Lengkap</label>
<input class="form-control type="text" name="nama_lengkap" placeholder="Nama Lengkap" />
</div>
</div>
<div class="form-group">
<label for="jenjang">Jenjang: </label>
<select class="form-control" name="jenjang">
<option>SD</option>
<option>SMP</option>
</select>
</div>
<div class="form-group">
<label for="sekolah_asal">Sekolah Asal</label>
<input class="form-control type="text" name="sekolah_asal" placeholder="sekolah asal" />
</div>
<div class="form-group">
<label for="agama">Agama: </label>
<select class="form-control" name="agama">
<option>Islam</option>
<option>Kristen</option>
<option>Hindu</option>
<option>Budha</option>
<option>Atheis</option>
</select>
</div>
<div class="form-group">
<label for="tmpt_lahir">Tempat Lahir</label>
<input class="form-control type="text" name="tmpt_lahir" placeholder="Tempat Lahir(kota)" />
</div>
<div class="form-group">
<label for="tgl_lahir">Tanggal Lahir</label>
<input class="form-control type="text" name="tgl_lahir" placeholder="dd/mm/yyyy" />
</div>
<div class="form-group">
<label for="jenis_kel">Jenis Kelamin: </label>
<br>
<label><input type="radio" name="jenis_kel" value="pria"> Laki-laki</label>
<br>
<label><input type="radio" name="jenis_kel" value="wanita"> Perempuan</label>
</div>
<div class="form-group">
<label for="alamat">Alamat: </label>
<textarea class="form-control" name="alamat" placeholder="alamat lengkap"></textarea>
</div>
<div class="form-group">
<label for="sekolah_tujuan">Sekolah Tujuan</label>
<input class="form-control type="text" name="sekolah_tujuan" placeholder="Nama sekolah tujuan" />
</div>
<input type="submit" class="btn btn-success" value="Daftar" name="input" />
</div>
</form>
<br>
<br>
</body>
-proses_edit.php
<?php
include("config.php");
$id=$_POST['siswa_id'];
$NISN = $_POST['NISN'];
$NIK = $_POST['NIK'];
$nama_lengkap = $_POST['nama_lengkap'];
$jenjang = $_POST['jenjang'];
$sekolah_asal = $_POST['sekolah_asal'];
$agama = $_POST['agama'];
$tmpt_lahir = $_POST['tmpt_lahir'];
$tgl_lahir = $_POST['tgl_lahir'];
$jenis_kel = $_POST['jenis_kel'];
$alamat = $_POST['alamat'];
$sekolah_tujuan = $_POST['sekolah_tujuan'];
$sql = "UPDATE siswa SET NISN='$NISN', NIK='$NIK', nama_lengkap='$nama_lengkap', jenjang='$jenjang', sekolah_asal='$sekolah_asal', agama='$agama', tmpt_lahir='$tmpt_lahir', tgl_lahir='$tgl_lahir', jenis_kel='$jenis_kel', alamat='$alamat', sekolah_tujuan='$sekolah_tujuan' WHERE siswa_id=$id";
$query = mysqli_query($db,$sql);
if($query)
{
// jika berhasil
echo "Data berhasil dimasukkan.";
header('Location: view.php');
}
else
{
//jika gagal
echo "Data gagal dimasukkan.";
}
?>
-proses-pendaftaran.php <?php
include("config.php");
$NISN = $_POST['NISN'];
$NIK = $_POST['NIK'];
$nama_lengkap = $_POST['nama_lengkap'];
$jenjang = $_POST['jenjang'];
$sekolah_asal = $_POST['sekolah_asal'];
$agama = $_POST['agama'];
$tmpt_lahir = $_POST['tmpt_lahir'];
$tgl_lahir = $_POST['tgl_lahir'];
$jenis_kel = $_POST['jenis_kel'];
$alamat = $_POST['alamat'];
$sekolah_tujuan = $_POST['sekolah_tujuan'];
$sql = "INSERT INTO siswa(NISN, NIK, nama_lengkap, jenjang, sekolah_asal, agama, tmpt_lahir, tgl_lahir, jenis_kel, alamat, sekolah_tujuan) VALUE('$NISN', '$NIK', '$nama_lengkap', '$jenjang','$sekolah_asal', '$agama','$tmpt_lahir', '$tgl_lahir','$jenis_kel', '$alamat', '$sekolah_tujuan')";
$query = mysqli_query($db,$sql);
if($query)
{
// jika berhasil
echo "Data berhasil dimasukkan.";
header('Location: index2.php');
}
else
{
//jika gagal
echo "Data gagal dimasukkan.";
}
?>
-register.php
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLFfFRrCh2SGp1DAUWJhPoHbZ-bX_FmpB-4Dp9fz_8vqsHOAjtIxPD1Af9_3RnEZyKafQE5L79uk-sKwZ9mqeI6AXPIQE-q-uyffCm0aoijawS3W3NkeWJwrHF2GiP4SN9uUnTWQ4QpuLu/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <?php include('server.php') ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Pendaftaran siswa online|</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top">
<div class="container">
<a class="navbar-brand" href="index.php">Pendaftaran Siswa Online</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="login.php">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="register.php">Register</a>
</li>
</ul>
</div>
</div>
</nav>
<div class='container' style='margin-top: 40px;'>
<div class='row'>
</div>
<div class='panel panel-default'>
<form action="register.php" method="POST">
<?php include('errors.php'); ?>
<div class='panel-body'>
<div class="form-group">
<label for="NISN">NISN</label>
<input type="text" class="form-control" name="NISN" value="<?php echo $NISN; ?>" placeholder="NISN">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" name="password1">
</div>
<div class="form-group">
<label for="password">Confirm Password</label>
<input type="password" class="form-control" name="password2">
</div>
<button class="btn btn-primary" value="reg" name="reg">REGISTER</button>
<a href="index.php" class="btn btn-link">Sign In</a>
</form>
</div>
</div>
</div>
</body>
</html>
</code></pre>
-server.php
<?php
session_start();
// initializing variables
$NISN = "";
$errors = array();
// connect to the database
$db = mysqli_connect('localhost', 'rumahbun_bobbi', 'bobbibobbibobbi', 'rumahbun_ppdb');
// REGISTER USER
if (isset($_POST['reg'])) {
// receive all input values from the form
$NISN = mysqli_real_escape_string($db, $_POST['NISN']);
$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($NISN)) { array_push($errors, "NISN is required"); }
if (empty($password1)) { array_push($errors, "Password is required"); }
if ($password1 != $password2) {
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 NISN and/or email
$user_check_query = "SELECT * FROM user WHERE NISN='$NISN' LIMIT 1";
$result = mysqli_query($db, $user_check_query);
$user = mysqli_fetch_assoc($result);
if ($user) { // if user exists
if ($user['NISN'] === $NISN) {
array_push($errors, "NISN already exists");
}
}
// Finally, register user if there are no errors in the form
if (count($errors) == 0) {
$password = md5($password1);//encrypt the password before saving in the database
$query = "INSERT INTO user (NISN, password)
VALUES('$NISN', '$password')";
mysqli_query($db, $query);
$_SESSION['NISN'] = $NISN;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}
}
// ...
if (isset($_POST['login_user'])) {
$NISN = mysqli_real_escape_string($db, $_POST['NISN']);
$password = mysqli_real_escape_string($db, $_POST['password']);
if (empty($NISN)) {
array_push($errors, "NISN is required");
}
if (empty($password)) {
array_push($errors, "Password is required");
}
if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM user WHERE NISN='$NISN'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$_SESSION['NISN'] = $NISN;
$_SESSION['success'] = "You are now logged in";
header('location: index2.php');
}else {
array_push($errors, "Wrong NISN/password combination");
}
}
}
?>
-view.php
<?php include("config.php"); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Pendaftaran siswa online|</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark static-top">
<div class="container">
<a class="navbar-brand" href="index.php">Pendaftaran Siswa Online</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarResponsive">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link" href="index.php?logout='1'">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<header>
<h2 align="center">FORMULIR PENDAFTARAN SISWA BARU 2019</h2>
</header>
<div class="container bg-light">
<p>
<?php
$sql = "SELECT * FROM siswa";
$query = mysqli_query($db, $sql);
$siswa = mysqli_fetch_array($query);
echo "<strong>Nama Lengkap</strong><br>";
echo $siswa['nama_lengkap']; echo "<br>";
echo "<br />";
echo "<strong>NISN</strong><br>";
echo $siswa['NISN']; echo "<br>";
echo "<br />";
echo "<strong>NIK</strong><br>";
echo $siswa['NIK']; echo "<br>";
echo "<br />";
echo "<strong>Jenjang</strong><br>";
echo $siswa['jenjang']; echo "<br>";
echo "<br />";
echo "<strong>Sekolah Asal</strong><br>";
echo $siswa['sekolah_asal']; echo "<br>";
echo "<br />";
echo "<strong>Agama</strong><br>";
echo $siswa['agama']; echo "<br>";
echo "<br />";
echo "<strong>Tempat Lahir</strong><br>";
echo $siswa['tmpt_lahir']; echo "<br>";
echo "<br />";
echo "<strong>tgl_lahir</strong><br>";
echo $siswa['tgl_lahir']; echo "<br>";
echo "<br />";
echo "<strong>Jenis Kelamin</strong><br>";
echo $siswa['jenis_kel']; echo "<br>";
echo "<br />";
echo "<strong>Alamat</strong><br>";
echo $siswa['alamat']; echo "<br>";
echo "<br />";
echo "<strong>Sekolah Tujuan</strong><br>";
echo $siswa['sekolah_tujuan']; echo "<br>";
echo "<br />";
echo "<a href='form_edit.php?id=".$siswa['siswa_id']."'>Edit</a> | ";
echo "<a href='hapus.php?id=".$siswa['siswa_id']."'>Hapus</a>";
?>
</div>
Dari kodingan di atas, didapatkan tampilan awal berikut:
Pertama, saya mencoba untuk melakukan registrasi terlebih dahulu
Setelah registrasi berhasil, maka akan langsung redirect ke login page, kemudian saya langsung memasukkan data yang sudah saya buat, dan sekarang menuju login page
Setelah itu, kita memasukkan data PPDB yang diperlukan, dan menekan tombol submit yang ada
Setelah berhasil memasukkan data, kita bisa mengecek dan memastikan bahwa data tersebut sudah benar dengan cara membuka view, hasilnya adalah
Fitur yang terakhir adalah download, stelah menekan tombol download maka setelahnya akan muncul seperti di bawah ini
Untuk melakukan download, kita hanya perlu menekan export, dan akan muncul pop up dialog
Sekian Terima Kasih :)
Comments
Post a Comment