Form Penginputan Prestasi Belajar Siswa
Faqih Fathan Irfani
05111740000175
Pweb-C
Form Penginputan
Source Code
1. Config.php
2.form-daftar.php
3.proses-edit.php
4.form-edit.php
5.list-siswa.php
6.proses-pendaftaran.php
7.hapus.php
8.index.php
05111740000175
Pweb-C
Form Penginputan
Halaman Awal
List/Data Hasil Penginputan
Penginputan Berhasil
Form edit Setelah data masuk
Source Code
1. Config.php
<?php
$server = "localhost";
$user = "root";
$password = "";
$nama_database = "rapor";
$db = mysqli_connect($server, $user, $password, $nama_database);
if( !$db ){
die("Gagal terhubung dengan database: " . mysqli_connect_error());
}
?>
2.form-daftar.php
<!DOCTYPE html>
<html>
<head>
<title>Selamat Datang Di Sistem Akademik</title>
</head>
<body>
<header>
<h3>Rapor hasil pembelajaran Siswa</h3>
</header>
<form action="proses-pendaftaran.php" method="POST">
<fieldset>
<p>
<label for="No_Induk">No.Induk: </label>
<input type="text" name="nama" placeholder="No_induk" />
</p>
<p>
<label for="Nama_lengkap">Nama Lengkap: </label>
<textarea name="Nama Lengkap"></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>
<label><input type="radio" name="Kelas" value="IPA"> IPA</label>
<label><input type="radio" name="Kelas" value="IPS"> IPS</label>
<label><input type="radio" name="Kelas" value="Bahasa"> Bahasa</label>
</p>
<p>
<label for="Semester">Semester: </label>
<select name="Semester">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
</select>
</p>
<p>
<label for="Prestasi">Prestasi: </label>
<select name="Prestasi">
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
<option>E</option>
</select>
</p>
<p>
<input type="submit" value="Daftar" name="daftar" />
</p>
</fieldset>
</form>
</body>
</html>
3.proses-edit.php
<?php
include("config.php");
// cek apakah tombol simpan sudah diklik atau blum?
if(isset($_POST['simpan'])){
// ambil data dari formulir
$id = $_POST['No_Induk'];
$nama = $_POST['Nama_Lengkap'];
$jk = $_POST['jenis_kelamin'];
$kelas = $_POST['Kelas'];
$Semester = $_POST['Semester'];
$Prestasi = $_POST['Prestasi'];
// buat query update
$sql = "UPDATE rapor_siswa SET No_Induk='$id', Nama_Lengkap='$nama',jenis_kelamin='$jk',Kelas='$kelas', Semester'$Semester', Prestasi='$Prestasi' 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...");
}
?>
4.form-edit.php
<?php
include("config.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 rapor_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 Edit</title>
</head>
<body>
<header>
<h3>Formulir Edit Siswa</h3>
</header>
<form action="proses-edit.php" method="POST">
<fieldset>
<input type="hidden" name="id" value="<?php echo $siswa['id'] ?>" />
<p>
<label for="No_Induk">No.Induk: </label>
<input type="text" name="nama" placeholder="No_Induk" value="<?php echo $siswa['No_Induk'] ?>" />
</p>
<p>
<label for="Nama_Lengkap">Nama Lengkap: </label>
<textarea name="Nama_Lengkap"><?php echo $siswa['Nama_Lengkap'] ?></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>
<?php $Kelas = $siswa['Kelas']; ?>
<label><input type="radio" name="Kelas" value="IPA" <?php echo ($Kelas == 'IPA') ? "checked": "" ?>> IPA</label>
<label><input type="radio" name="Kelas" value="IPS" <?php echo ($Kelas == 'IPS') ? "checked": "" ?>> IPS</label>
<label><input type="radio" name="Kelas" value="Bahasa" <?php echo ($Kelas == 'Bahasa') ? "checked": "" ?>> Bahasa</label>
</p>
<p>
<label for="Semester">Semester: </label>
<?php $Semester = $siswa['Semester']; ?>
<select name="agama">
<option <?php echo ($Semester == '1') ? "selected": "" ?>>1</option>
<option <?php echo ($Semester == '2') ? "selected": "" ?>>2</option>
<option <?php echo ($Semester == '3') ? "selected": "" ?>>3</option>
<option <?php echo ($Semester == '4') ? "selected": "" ?>>4</option>
<option <?php echo ($Semester == '5') ? "selected": "" ?>>5</option>
<option <?php echo ($Semester == '6') ? "selected": "" ?>>6</option>
</select>
</p>
<p>
<label for="Prestasi">Prestasi: </label>
<?php $Prestasi = $siswa['Prestasi']; ?>
<select name="agama">
<option <?php echo ($Prestasi == 'A') ? "selected": "" ?>>A</option>
<option <?php echo ($Prestasi == 'B') ? "selected": "" ?>>B</option>
<option <?php echo ($Prestasi == 'C') ? "selected": "" ?>>C</option>
<option <?php echo ($Prestasi == 'D') ? "selected": "" ?>>D</option>
<option <?php echo ($Prestasi == 'E') ? "selected": "" ?>>E</option>
</select>
</p>
<p>
<input type="submit" value="Simpan" name="simpan" />
</p>
</fieldset>
</form>
</body>
</html>
5.list-siswa.php
<?php include("config.php"); ?>
<!DOCTYPE html>
<html>
<head>
<title>Sistem Akademik</title>
</head>
<body>
<header>
<h3>Rapor Siswa</h3>
</header>
<nav>
<a href="form-daftar.php">[+] Tambah Baru</a>
</nav>
<br>
<table border="1">
<thead>
<tr>
<th>No. Induk</th>
<th>Nama Lengkap</th>
<th>Jenis Kelamin</th>
<th>Kelas</th>
<th>Semester</th>
<th>Prestasi</th>
<th>Tindakan</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM rapor_siswa";
$query = mysqli_query($db, $sql);
while($siswa = mysqli_fetch_array($query)){
echo "<tr>";
echo "<td>".$siswa['No_Induk']."</td>";
echo "<td>".$siswa['Nama_Lengkap']."</td>";
echo "<td>".$siswa['jenis_kelamin']."</td>";
echo "<td>".$siswa['Kelas']."</td>";
echo "<td>".$siswa['Semester']."</td>";
echo "<td>".$siswa['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: <?php echo mysqli_num_rows($query) ?></p>
</body>
</html>
6.proses-pendaftaran.php
<?php
include("config.php");
if(isset($_POST['daftar'])){
// ambil data dari formulir
$id = $_POST['No_induk'];
$Nama = $_POST['Nama_Lengkap'];
$jk = $_POST['jenis_kelamin'];
$Kelas = $_POST['Kelas'];
$Semester = $_POST['Semester'];
$Prestasi = $_POST['Prestasi'];
$sql = "INSERT INTO rapor_siswa (No_Induk, Nama_Lengkap, jenis_kelamin, Kelas, Semester, Prestasi) VALUE ('$id','$nama','$jk','$kelas','$Semester','$Prestasi')";
$query = mysqli_query($db, $sql);
if( $query ) {
echo "Sukses!!";
header('Location: index.php?status=sukses');
} else {
echo "Gagal!!";
header('Location: index.php?status=gagal');
}
} else {
die("Akses dilarang...");
}
?>
7.hapus.php
<?php
include("config.php");
if( isset($_GET['id']) ){
$id = $_GET['id'];
$sql = "DELETE FROM rapor_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...");
}
?>
8.index.php
<!DOCTYPE html>
<html>
<head>
<title>Sistem Akademik</title>
</head>
<body>
<header>
<h3>Selamat Datang di</h3>
<h1>Sistem Akademik</h1>
</header>
<h4>Menu</h4>
<nav>
<?php if(isset($_GET['status'])): ?>
<p>
<?php
if($_GET['status'] == 'sukses'){
echo "Penginputan Data berhasil!";
} else {
echo "Penginputan gagal!";
}
?>
</p>
<?php endif; ?>
<ul>
<li><a href="form-daftar.php">Masukkan Data Siswa</a></li>
<li><a href="list-siswa.php">Data</a></li>
</ul>
</nav>
</body>
</html>
Komentar
Posting Komentar