Ini merupakan UTS PWEB C.
index.php:
config.php:
proses.php:
index.php:
<!DOCTYPE html>
<html>
<head>
<title>E-Rapor</title>
<style type="text/css">
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 0;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #f1f1f1;
}
</style>
</head>
<body>
<div class="dropdown">
<button class="dropbtn">Input Data dan Nilai</button>
<div class="dropdown-content">
<a href="#">Input Kehadiran Siswa</a>
<a href="#">Input Nilai Ekstrakulikuler</a>
<a href="index.php">Input Prestasi</a>
</div>
</div>
<div>
<br><br><br>
<form action="" method="POST" >
<table>
<tr>
<td>Kelas</td>
<td><select>>
<option value="xmiai">X MIA I</option>
<option value="xmiaii">X MIA II</option>
</select>
</td>
</tr>
<tr>
<td>Semester</td>
<td><select>
<option value="sem1">Semester 1</option>
<option value="sem2">Semester 2</option>
<option value="sem3">Semester 3</option>
<option value="sem4">Semester 4</option>
<option value="sem5">Semester 5</option>
<option value="sem6">Semester 6</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="Tambahkan" name="tambah" /></td>
</tr>
</table>
</form>
</div>
<div>
<br><br>
<table>
<form action="proses.php" method="POST">
<tr>
<td>Nama Siswa</td>
<td><input type="text" name="name"> </td>
</tr>
<tr>
<td>Jenis Prestasi</td>
<td><input type="text" name="jprestasi"></td>
</tr>
<tr>
<td>Keterangan</td>
<td><input type="Text" name="keterangan"></td>
</tr>
<tr>
<td><br><input type="submit" value="Simpan" name="simpan"></td>
</tr>
</form>
</table>
</div>
</body>
</html>
config.php:
<?php
$server = "localhost";
$user = "root";
$password = "";
$nama_database = "prestasi_siswa";
$db = mysqli_connect($server,$user,$password,$nama_database);
if(!$db){
die("Gagal terhubung dengan database: " .mysql_connect_error());
}
?>
proses.php:
<?php
include("config.php");
// cek apakah tombol daftar sudah diklik atau blum?
if(isset($_POST['simpan'])){
// ambil data dari formulir
$nama = $_POST['name'];
$prestasi = $_POST['jprestasi'];
$ket = $_POST['keterangan'];
// buat query
$sql = "INSERT INTO daftar_prestasi (nama_siswa, jenis_prestasi, keterangan VALUE ('$nama', '$prestasi', '$ket')";
$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...");
}
?>
Komentar
Posting Komentar