Nama : Bobbi Aditya
NRP : 05111740000099
Kelas : PWEB C
Dalam tugas ini, saya membuat form untuk mengisikan nilai siswa, berdasarkan data siswa yang sudah tersedia.
Dalam project ini , saya memiliki 7 file:
1. config.php
2. index.php
3. list-siswa.php
4. rapor.php
5. form-rapor.php
6. proses-daftar.php
7. hapus.php
Berikut saya sertakan source code hasil yang sudah saya kerjakan.
config.php
<?php
$server = "localhost";
$user = "root";
$password = "";
$nama_database = "rapor_siswa";
$db = mysqli_connect($server, $user, $password, $nama_database);
if( !$db ){
die("Gagal terhubung dengan database: " . mysqli_connect_error());
}
?>
Index.php <!DOCTYPE html>
<html>
<head>
<title>Input Rapor Siswa|| SMA PetaniCoding</title>
</head>
<body style="text-align: center;">
<header>
<h3>Input Rapor Siswa</h3>
<h1>SMA PetaniCoding</h1>
</header>
<h4>Menu</h4>
<nav>
<a href="list-siswa.php">Data Siswa</a>
<br>
<a href="form-rapor.php">Input Data Rapor</a>
<br>
<a href="rapor.php">Data Rapor</a>
</nav>
<?php if(isset($_GET['status'])): ?>
<p>
<?php
if($_GET['status'] == 'sukses'){
echo "Input rapor siswa berhasil!";
} else {
echo "Input rapor siswa gagal!";
}
?>
</p>
<?php endif; ?>
</body>
</html>
list-siswa.php <?php include("config.php"); ?>
<!DOCTYPE html>
<html>
<head>
<title>Input Rapor Siswa || SMA PetaniCoding</title>
</head>
<body style="text-align: center;">
<header>
<h3>Siswa yang terdaftar</h3>
</header>
<br>
<table border="1" align="center">
<thead>
<tr>
<th>Nama</th>
<th>Nomor Induk</th>
<th>Jenis Kelamin</th>
<th>Kelas</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM data_siswa";
$query = mysqli_query($db, $sql);
while($siswa = mysqli_fetch_array($query)){
echo "<tr>";
echo "<td>".$siswa['Nama']."</td>";
echo "<td>".$siswa['Nomor_Induk']."</td>";
echo "<td>".$siswa['Jenis_Kelamin']."</td>";
echo "<td>".$siswa['Kelas']."</td>";
echo "</tr>";
// echo "<td>";
// echo "<a href='index.php?'>kembali</a> | ";
// echo "</td>";
}
?>
</tbody>
</table>
<a href="index.php">Kembali ke Halaman Utama</a>
<p>Total: <?php echo mysqli_num_rows($query) ?></p>
</body>
</html>
rapor.php <?php include("config.php"); ?>
<!DOCTYPE html>
<html>
<head>
<title>Input Rapor Siswa || SMA PetaniCoding</title>
</head>
<body style="text-align: center;">
<header>
<h3>Siswa yang terdaftar</h3>
</header>
<br>
<table border="1" align="center">
<thead>
<tr>
<th>Nama</th>
<th>Nomor Induk</th>
<th>Jenis Kelamin</th>
<th>Kelas</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM data_siswa";
$query = mysqli_query($db, $sql);
while($siswa = mysqli_fetch_array($query)){
echo "<tr>";
echo "<td>".$siswa['Nama']."</td>";
echo "<td>".$siswa['Nomor_Induk']."</td>";
echo "<td>".$siswa['Jenis_Kelamin']."</td>";
echo "<td>".$siswa['Kelas']."</td>";
echo "</tr>";
// echo "<td>";
// echo "<a href='index.php?'>kembali</a> | ";
// echo "</td>";
}
?>
</tbody>
</table>
<a href="index.php">Kembali ke Halaman Utama</a>
<p>Total: <?php echo mysqli_num_rows($query) ?></p>
</body>
</html>
form-rapor.php <!DOCTYPE html>
<html>
<head>
<title>Input Rapor Siswa ||SMA PetaniCoding</title>
</head>
<body style="text-align: center;">
<header>
<h3>Input Rapor Siswa </h3>
</header>
<form action="proses_daftar.php" method="POST" style="border: 2px black solid">
<p>
<label for="Nama">Nama: </label>
<input type="text" name="Nama" placeholder="Nama" />
</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_Sakit" />
</p>
<p>
<label for="Total_Absen">Total Absen: </label>
<input type="number" name="Total_Absen" placeholder="Total_Absen" />
</p>
<p>
<label for="Nama_Ekstra">Nama Ekstrakurikuler: </label>
<input type="text" name="Nama_Ekstra" placeholder="Nama_Ekstra" />
</p>
<p>
<p>
<label for="Nilai_Ekstra">Nilai Ekstrakuriluer: </label>
<input type="number" name="Nilai_Ekstra" placeholder="Nilai_Ekstra" />
</p>
<p>
<label for="Poin_Pres">Total Poin Prestasi: </label>
<input type="number" name="Poin_Pres" placeholder="Poin_Pres" />
</p>
<p>
<label for="Deskripsi">Deskripsi Prestasi: </label>
<textarea name="Deskripsi"></textarea>
</p>
<p>
<input type="submit" value="Input" name="daftar" />
</p>
</fieldset>
</form>
</body>
</html>
proses_daftar.php <?php
include("config.php");
if(isset($_POST['daftar'])){
$nama = $_POST['Nama'];
$Total_Ijin = $_POST['Total_Ijin'];
$Total_Sakit = $_POST['Total_Sakit'];
$Total_Absen = $_POST['Total_Absen'];
$Nama_Ekstra = $_POST['Nama_Ekstra'];
$Nilai_Ekstra = $_POST['Nilai_Ekstra'];
$Poin_Pres = $_POST['Poin_Pres'];
$Deskripsi = $_POST['Deskripsi'];
$sql = "INSERT INTO data_prestasi (Nama, Total_Ijin, Total_Sakit, Total_Absen, Nama_Ekstra, Nilai_Ekstra, Poin_Pres, Deskripsi ) VALUE ('$nama', '$Total_Ijin', '$Total_Sakit', '$Total_Absen', '$Nama_Ekstra','$Nilai_Ekstra', '$Poin_Pres', '$Deskripsi')";
$query = mysqli_query($db, $sql);
if( $query ) {
echo "Pendaftaran Sukses!!";
header('Location: index.php?status=sukses');
} else {
echo "Pendaftaran Gagal!!";
header('Location: index.php?status=gagal');
}
} else {
die("Akses dilarang...");
}
?>
hapus.php <?php
include("config.php");
if( isset($_GET['id']) ){
// ambil id dari query string
$id = $_GET['id'];
// buat query hapus
$sql = "DELETE FROM data_prestasi WHERE id=$id";
$query = mysqli_query($db, $sql);
// apakah query hapus berhasil?
if( $query ){
header('Location: rapor.php');
} else {
die("gagal menghapus...");
}
} else {
die("akses dilarang...");
}
?>
Hasil Screenshot
Tampilan awalnya
Tampilan data rapor
Tampilan pada saat input data rapor
Tampilan data rapor setelah diinput
Tampilan data rapor setelah di hapus
Comments
Post a Comment