Nama : Reza Adipatria Maranatha
Tampilan untuk memasukkan data
Tampilan untuk Edit data
Tampilan setelah di hapus datanya
Tampilan sebelum di hapus
NRP : 05111740000186
Kelas : PWEB C
UTS hari ini saya diberi tugas untuk membuat sebuah report online untuk memasukkan data siswa
saya membuat database dengan nama pendaftaran_siswa dan tabel calon_siswa
berikut hasil run dari web saya :
Tampilan awal
Tampilan untuk memasukkan data
Tampilan untuk Edit data
Tampilan setelah di hapus datanya
Tampilan sebelum di hapus
Source code
Index.php
<!DOCTYPE html>
<html>
<head>
<title>E-Report | SMAK ST LOUIS 1</title>
</head>
<style type="text/css">
nav{
text-align: center;
}
nav ul{
display: table;margin: 0 auto;
}
body{
background-color: #ff9900;
}
div{
background-color: #ffcc80;
padding: 5px;
}
</style>
<body>
<div>
<header>
<h3 align="center">E-Report</h3>
<h1 align="center">SMAK ST LOUIS 1</h1>
</header>
<h4 align="center">Menu</h4>
<nav>
<ul>
<li><a href="list-siswa.php">Student Report</a></li>
</ul>
</nav>
</div>
</body>
</html>
list-siswa.php
<?php include("config.php"); ?>
<!DOCTYPE html>
<html>
<head>
<title>E-Report | SMAK ST LOUIS 1</title>
</head>
<style type="text/css">
th,td{
padding: 15px;
}
table{
text-align: center;
}
body{
background-color: #ff9900;
}
</style>
<body>
<header>
<h3>List Siswa</h3>
</header>
<nav>
<a href="form-daftar.php">[+] Add New Student</a>
</nav>
<br>
<table border="1px">
<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>Alamat</th>
<th>Jenis Kelamin</th>
<th>Kelas</th>
<th>Total Ijin</th>
<th>Total Sakit</th>
<th>Total Absen</th>
<th>Jenis Prestasi</th>
<th>Keterangan Prestasi</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM calon_siswa";
$query = mysqli_query($db, $sql);
while($siswa = mysqli_fetch_array($query)){
echo "<tr>";
echo "<td>".$siswa['ID']."</td>";
echo "<td>".$siswa['nama']."</td>";
echo "<td>".$siswa['alamat']."</td>";
echo "<td>".$siswa['jenis_kelamin']."</td>";
echo "<td>".$siswa['Kelas']."</td>";
echo "<td>".$siswa['Total_Ijin']."</td>";
echo "<td>".$siswa['Total_Sakit']."</td>";
echo "<td>".$siswa['Total_Absen']."</td>";
echo "<td>".$siswa['Jenis_Prestasi']."</td>";
echo "<td>".$siswa['Keterangan_Prestasi']."</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 Siswa: <?php echo mysqli_num_rows($query) ?></p>
</body>
</html>
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());
}
?>
hapus.php
<?php
include("config.php");
if( isset($_GET['id']) ){
$id = $_GET['id'];
$sql = "DELETE FROM calon_siswa WHERE id=$id";
$query = mysqli_query($db, $sql);
if( $query ){
header('Location: list-siswa.php');
} else {
die("gagal menghapus...");
}
} else {
die("akses dilarang...");
}
?>
form-daftar.php
<!DOCTYPE html>
<html>
<head>
<title>E-Report | SMAK ST LOUIS 1</title>
</head>
<style type="text/css">
body{
background-color: #ff9900;
}
label{
padding : 5px;
margin-right: 20px;
}
</style>
<body>
<header>
<h2 align="center">E-Report</h2>
</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="kelas">Kelas: </label>
<input type="text" name="kelas" placeholder="Kelas" />
</p>
<p>
<label for="Total_Ijin">Total Ijin: </label>
<input type="number" name="Total_Ijin" placeholder="Total_Ijin" />
</p>
<p>
<label for="Total_Sakit">Total Sakit: </label>
<input type="number" name="Total_Sakit" placeholder="Total_Absen" />
</p>
<p>
<label for="Total_Absen">Total Absen: </label>
<input type="number" name="Total_Absen" placeholder="Total_Absen" />
</p>
<p>
<label for="Jenis_Prestasi">Jenis Prestasi: </label>
<textarea name="Jenis_Prestasi"></textarea>
</p>
<p>
<label for="Keterangan_Prestasi">Keterangan Prestasi: </label>
<textarea name="Keterangan_Prestasi"></textarea>
</p>
<p>
<input type="submit" value="Daftar" name="daftar" />
</p>
</fieldset>
</form>
</body>
</html>
proses-pendaftaran.php
<?php
include("config.php");
if(isset($_POST['daftar'])){
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$jk = $_POST['jenis_kelamin'];
$kelas = $_POST['kelas'];
$total_ijin = $_POST['Total_Ijin'];
$total_sakit = $_POST['Total_Sakit'];
$total_absen = $_POST['Total_Absen'];
$jenisprestasi = $_POST['Jenis_Prestasi'];
$keterangan = $_POST['Keterangan_Prestasi'];
$sql = "INSERT INTO calon_siswa (nama, alamat, jenis_kelamin, kelas,Total_Ijin, Total_Sakit, Total_Absen,Jenis_Prestasi,Keterangan_Prestasi) VALUE ('$nama', '$alamat', '$jk', '$kelas', '$total_ijin','$total_sakit','$total_absen','$jenisprestasi','keterangan')";
$query = mysqli_query($db, $sql);
if( $query ) {
header('Location: index.php?status=sukses');
} else {
header('Location: index.php?status=gagal');
}
} else {
die("Akses dilarang...");
}
?>
form-edit.php
<?php
include("config.php");
if( !isset($_GET['id']) ){
header('Location: list-siswa.php');
}
$id = $_GET['id'];
$sql = "SELECT * FROM calon_siswa WHERE id=$id";
$query = mysqli_query($db, $sql);
$siswa = mysqli_fetch_assoc($query);
if( mysqli_num_rows($query) < 1 ){
die("data tidak ditemukan...");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>E-Report | SMAK ST LOUIS 1</title>
</head>
<style type="text/css">
body{
background-color: #ff9900;
}
label{
padding : 5px;
margin-right: 20px;
}
</style>
<body>
<header>
<h2 align="center">E-Report</h2>
</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="kelas">Kelas: </label>
<input type="text" name="Kelas" placeholder="kelas" value="<?php echo $siswa['Kelas'] ?>" />
</p>
<p>
<label for="Total_Ijin">Total Ijin: </label>
<input type="number" name="Total_Ijin" placeholder="Total_Ijin" value="<?php echo $siswa['Total_Ijin'] ?>" />
</p>
<p>
<label for="Total_Sakit">Total Sakit: </label>
<input type="number" name="Total_Sakit" placeholder="Total_Sakit" value="<?php echo $siswa['Total_Sakit'] ?>" />
</p>
<p>
<label for="Total_Absen">Total Absen: </label>
<input type="number" name="Total_Absen" placeholder="Total_Absen" value="<?php echo $siswa['Total_Absen'] ?>" />
</p>
<p>
<label for="Jenis_Prestasi">Jenis Prestasi: </label>
<input type="text" name="Jenis_Prestasi" placeholder="Jenis_Prestasi" value="<?php echo $siswa['Jenis_Prestasi'] ?>" />
</p>
<p>
<label for="Keterangan_Prestasi">Keterangan Prestasi: </label>
<input type="text" name="Keterangan_Prestasi" placeholder="Keterangan_Prestasi" value="<?php echo $siswa['Keterangan_Prestasi'] ?>" />
</p>
<p>
<input type="submit" value="Simpan" name="simpan" />
</p>
</fieldset>
</form>
</body>
</html>
proses-edit.php
<?php
include("config.php");
if(isset($_POST['simpan'])){
$id = $_POST['id'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$jk = $_POST['jenis_kelamin'];
$kelas = $_POST['Kelas'];
$total_ijin = $_POST['Total_Ijin'];
$total_sakit = $_POST['Total_Sakit'];
$total_absen= $_POST['Total_Absen'];
$jenis_prestasi = $_POST['Jenis_Prestasi'];
$keterangan = $_POST['Keterangan_Prestasi'];
$sql = "UPDATE calon_siswa SET nama='$nama', alamat='$alamat', jenis_kelamin='$jk', Kelas='$kelas', Total_Ijin='$total_ijin',Total_Sakit= '$total_sakit',Total_Absen='$total_absen',Jenis_Prestasi='$jenis_prestasi',Keterangan_Prestasi='$keterangan' WHERE ID=$id";
$query = mysqli_query($db, $sql);
if( $query ) {
header('Location: list-siswa.php');
} else {
die("Gagal menyimpan perubahan...");
}
} else {
die("Akses dilarang...");
}
?>
Comments
Post a Comment