Tugas kali ini adalah membuat website yang mengimplementasikan PHP. Penggunaan PHP adalah dengan tujuan HTML biasa dapat berinteraksi dengan database sehingga data yang ditampilkan bisa bersifat dinamis. Dalam pengerjaannya digunakan sedikit Bootstrap, CSS, HTML, PHP, dan SQL. Laman website sendiri bisa diakses pada link berikut.
Terdapat tiga halaman utama, yaitu Login, List siswa dan Form. Untuk form digunakan ketika ingin menambah data baru serta ketika akan melakukan update.
Source Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$server = "localhost"; | |
$user = "root"; | |
$password = ""; | |
$nama_database = "tetsuya_senior_high_school"; | |
$db = mysqli_connect($server, $user, $password, $nama_database); | |
if( !$db ){ | |
die("Gagal terhubung dengan database: " . mysqli_connect_error()); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Initialize the session | |
session_start(); | |
// Check if the user is already logged in, if yes then redirect him to welcome page | |
if(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){ | |
header("location: home.php"); | |
exit; | |
} | |
// Include config file | |
require_once "config.php"; | |
// Define variables and initialize with empty values | |
$username = $password = ""; | |
$username_err = $password_err = ""; | |
// Processing form data when form is submitted | |
if($_SERVER["REQUEST_METHOD"] == "POST"){ | |
// Check if username is empty | |
if(empty(trim($_POST["username"]))){ | |
$username_err = "Please enter username."; | |
} else{ | |
$username = trim($_POST["username"]); | |
} | |
// Check if password is empty | |
if(empty(trim($_POST["password"]))){ | |
$password_err = "Please enter your password."; | |
} else{ | |
$password = trim($_POST["password"]); | |
} | |
error_reporting(E_ERROR | E_PARSE); | |
// Validate credentials | |
if(empty($username_err) && empty($password_err)){ | |
// Prepare a select statement | |
$sql = "SELECT * FROM users WHERE username = '$username'"; | |
$query = mysqli_query($db, $sql); | |
$num_data = mysqli_num_rows($query); | |
if($num_data == 1) { | |
$admin = mysqli_fetch_array($query); | |
if($password == $admin['password']) { | |
// Password is correct, so start a new session | |
session_start(); | |
// Store data in session variables | |
$_SESSION["loggedin"] = true; | |
$_SESSION["id"] = $admin['id']; | |
$_SESSION["username"] = $username; | |
// Redirect user to welcome page | |
header("location: home.php"); | |
} else{ | |
// Display an error message if password is not valid | |
$password_err = "Invalid username or password."; | |
} | |
} else { | |
$password_err = "Invalid username or password."; | |
} | |
} | |
// Close connection | |
mysqli_close($db); | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="author" content="Axel"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<!-- Bootstrap CSS --> | |
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> | |
<title>Login - TSHS</title> | |
<style type="text/css"> | |
body { | |
margin: 0px; | |
padding: 0px; | |
} | |
.login-container { | |
height: 100vh; | |
width: 100%; | |
display: flex; | |
} | |
.equal-content { | |
flex: 50%; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
} | |
.left-side { | |
background-color: #EFABA1; | |
} | |
.right-side { | |
display: flex; | |
padding: 0 8rem; | |
flex-direction: column; | |
align-items: center; | |
} | |
.school-name { | |
color: #FF4B35; | |
font-size: 4rem; | |
} | |
.login-form-container { | |
width: 100%; | |
display: flex; | |
flex-direction: column; | |
} | |
.orange-button { | |
background-color: #FE705F; | |
width: 100%; | |
text-align: center; | |
color: #fff; | |
border: none; | |
padding: 0.5rem 1rem; | |
border-radius: 5px; | |
font-size: 1rem; | |
cursor: pointer; | |
text-decoration: none; | |
} | |
.orange-button:hover { | |
background-color: #E46657; | |
color: #fff; | |
text-decoration: none; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="login-container border border-primary"> | |
<div class="equal-content left-side"> | |
<img src="assets/login_art.png" alt="Tetsuya Senior High School" class="img-fluid"> | |
</div> | |
<div class="equal-content right-side"> | |
<h1 class="school-name border-bottom border-dark pb-4 mb-5"><strong>Tetsuya Senior High School</strong><span><img src="assets/school_logo_board.svg" height="60" style="margin-right: 0.5rem;"/></span></h1> | |
<a type="submit" class="orange-button mt-3 mb-3"> | |
<span><img src="assets/its_logo.svg" height="30" style="margin-right: 0.5rem;"/></span> | |
Masuk dengan myITS</a> | |
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" class="login-form-container" method="post"> | |
<div class="mb-3 form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>"> | |
<label for="input-username" class="form-label">Username</label> | |
<input type="text" name="username" class="form-control" id="input-username" value="<?php echo $username; ?>"> | |
<span class="help-block"><?php echo $username_err; ?></span> | |
</div> | |
<div class="mb-3 form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>"> | |
<label for="input-password" class="form-label">Password</label> | |
<input type="password" name="password" class="form-control" id="input-password" value="<?php echo '' ?>"> | |
<span class="help-block"><?php echo $password_err; ?></span> | |
</div> | |
<button type="submit" class="orange-button">Login</button> | |
</form> | |
</div> | |
</div> | |
<!-- Option 1: Bootstrap Bundle with Popper --> | |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Initialize the session | |
session_start(); | |
// Unset all of the session variables | |
$_SESSION = array(); | |
// Destroy the session. | |
session_destroy(); | |
// Redirect to login page | |
header("location: login.php"); | |
exit; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Initialize the session | |
session_start(); | |
// Check if the user is logged in, if not then redirect him to login page | |
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){ | |
header("location: login.php"); | |
exit; | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Dashboard - TSHS</title> | |
<meta charset="UTF-8"> | |
<meta name="author" content="Axel"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> | |
<style type="text/css"> | |
html, body { | |
margin: 0; | |
padding: 0; | |
} | |
.home-container { | |
height: 100vh; | |
width: 100%; | |
padding: 0rem 12rem; | |
display: flex; | |
flex-direction: column; | |
align-items: center; | |
justify-content: center; | |
} | |
.home-title { | |
color: #FF4B35; | |
font-size: 3em; | |
font-weight: bold; | |
} | |
.orange-button { | |
background-color: #FE705F; | |
width: 50%; | |
text-align: center; | |
color: #fff; | |
border: none; | |
padding: 0.5rem 1rem; | |
border-radius: 5px; | |
font-size: 1rem; | |
cursor: pointer; | |
text-decoration: none; | |
} | |
.orange-button:hover { | |
background-color: #E46657; | |
color: #fff; | |
text-decoration: none; | |
} | |
.notifikasi { | |
color: #FF4B35; | |
} | |
footer { | |
margin-top: 250px; | |
color: #FF4B35; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="home-container"> | |
<h2 class="home-title mb-5">Dashboard Admin</h2><br> | |
<a class="orange-button mb-3" href="student_add.php">Tambah Siswa</a> | |
<a class="orange-button mb-3" href="student_list.php">Lihat daftar siswa</a> | |
<a class="orange-button mb-3" href="#">Tambah Guru</a> | |
<a class="orange-button mb-3" href="#">Lihat daftar guru</a> | |
<a class="orange-button mb-3" href="#">Tambah orang tua siswa</a> | |
<a class="orange-button mb-3" href="#">Lihat daftar orang tua siswa</a> | |
<a class="orange-button mb-3" href="#">Ubah slip pembayaran</a> | |
<a class="orange-button mb-3" href="#">Cetak slip pembayaran</a> | |
<br> | |
<a class="orange-button mb-3" href="logout.php">Sign Out</a> | |
<?php if(isset($_GET['status'])): ?> | |
<p> | |
<?php | |
if($_GET['status'] == 'sukses'){ | |
echo "<p class='text-center notifikasi'>Pendaftaran siswa baru berhasil!</p>"; | |
} else { | |
echo "<p class='text-center notifikasi'>Pendaftaran gagal!</p>"; | |
} | |
?> | |
</p> | |
<?php endif; ?> | |
</div> | |
<!-- Option 1: Bootstrap Bundle with Popper --> | |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Initialize the session | |
session_start(); | |
// Check if the user is logged in, if not then redirect him to login page | |
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){ | |
header("location: login.php"); | |
exit; | |
} | |
?> | |
<?php include("config.php"); ?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Pendaftaran Siswa Baru</title> | |
<meta charset="UTF-8"> | |
<meta name="author" content="Axel"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> | |
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script> | |
<style type="text/css"> | |
html, body { | |
margin: 0; | |
padding: 0; | |
} | |
.home-title { | |
color: #FF4B35; | |
margin-top: 3rem; | |
font-size: 3em; | |
font-weight: bold; | |
} | |
.student-add-container { | |
width: 100%; | |
padding: 0rem 12rem; | |
display: flex; | |
flex-direction: column; | |
align-items: center; | |
justify-content: center; | |
} | |
.login-form-container { | |
width: 60%; | |
display: flex; | |
flex-direction: column; | |
} | |
.orange-button { | |
background-color: #FE705F; | |
width: 100%; | |
text-align: center; | |
color: #fff; | |
border: none; | |
padding: 0.5rem 1rem; | |
border-radius: 5px; | |
font-size: 1rem; | |
cursor: pointer; | |
text-decoration: none; | |
} | |
.orange-button:hover { | |
background-color: #E46657; | |
color: #fff; | |
text-decoration: none; | |
} | |
.rounded-card-table { | |
background-color: #F4F3F3; | |
border-radius: 0.5rem; | |
} | |
.head-table { | |
padding: 1rem 3rem; | |
} | |
td, th { | |
text-align: center; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="student-add-container"> | |
<h1 class="home-title text-center">Daftar Siswa<br/>Tetsuya Senior High School</h1> | |
<nav class="text-center"> | |
<a href="student_add.php">[+] Tambah Baru</a> | |
</nav> | |
<br> | |
<table class="table table-borderless rounded-card-table"> | |
<thead class="border-bottom"> | |
<tr class="head-table"> | |
<th scope="col">No</th> | |
<th scope="col">Nama</th> | |
<th scope="col">NIP</th> | |
<th scope="col-2">Alamat</th> | |
<th scope="col">Phone</th> | |
<th scope="col">Gender</th> | |
<th scope="col">Tindakan</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php | |
$sql = "SELECT * FROM students"; | |
$query = mysqli_query($db, $sql); | |
$sequence = 1; | |
while($siswa = mysqli_fetch_array($query)){ | |
echo "<tr>"; | |
echo "<td>".$sequence."</td>"; | |
echo "<td>".$siswa['nama']."</td>"; | |
echo "<td>".$siswa['nip']."</td>"; | |
echo "<td>".$siswa['alamat']."</td>"; | |
echo "<td>".$siswa['phone']."</td>"; | |
echo "<td>".$siswa['gender']."</td>"; | |
echo "<td>"; | |
echo "<a href='student_edit.php?id=".$siswa['id']."'>Edit</a> | "; | |
echo "<a href='student_delete.php?id=".$siswa['id']."'>Hapus</a>"; | |
echo "</td>"; | |
echo "</tr>"; | |
$sequence++; | |
} | |
?> | |
</tbody> | |
</table> | |
<p>Total: <?php echo mysqli_num_rows($query) ?></p> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Initialize the session | |
session_start(); | |
// Check if the user is logged in, if not then redirect him to login page | |
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){ | |
header("location: login.php"); | |
exit; | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Add New Student - TSHS</title> | |
<meta charset="UTF-8"> | |
<meta name="author" content="Axel"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> | |
<style type="text/css"> | |
html, body { | |
margin: 0; | |
padding: 0; | |
} | |
.home-title { | |
color: #FF4B35; | |
margin-top: 3rem; | |
font-size: 3em; | |
font-weight: bold; | |
} | |
.student-add-container { | |
width: 100%; | |
padding: 0rem 12rem; | |
display: flex; | |
flex-direction: column; | |
align-items: center; | |
justify-content: center; | |
} | |
.login-form-container { | |
width: 60%; | |
display: flex; | |
flex-direction: column; | |
} | |
.orange-button { | |
background-color: #FE705F; | |
width: 100%; | |
text-align: center; | |
color: #fff; | |
border: none; | |
padding: 0.5rem 1rem; | |
border-radius: 5px; | |
font-size: 1rem; | |
cursor: pointer; | |
text-decoration: none; | |
} | |
.orange-button:hover { | |
background-color: #E46657; | |
color: #fff; | |
text-decoration: none; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="student-add-container"> | |
<h1 class="home-title">Add New Student</h1> | |
<form action="student_add_control.php" class="login-form-container" method="post"> | |
<div class="mb-3 form-group"> | |
<label for="input-nama" class="form-label">Nama</label> | |
<input type="text" name="nama" class="form-control" id="input-nama"> | |
</div> | |
<div class="mb-3 form-group"> | |
<label for="input-nip" class="form-label">NIP</label> | |
<input type="text" name="nip" class="form-control" id="input-nip"> | |
</div> | |
<div class="form-group"> | |
<label for="input-alamat" class="form-label">Alamat</label> | |
<textarea class="form-control" name="alamat"></textarea> | |
</div> | |
<div class="mb-3 form-group"> | |
<label for="input-phone" class="form-label">Phone</label> | |
<input type="phone" name="phone" class="form-control" id="input-phone"> | |
</div> | |
<div class="form-group"> | |
<label for="gender">Jenis Kelamin</label> | |
<select class="form-control" name="gender"> | |
<option selected>Select your gender</option> | |
<option value="Laki-laki">Laki-laki</option> | |
<option value="Perempuan">Perempuan</option> | |
</select> | |
</div> | |
<div class="form-group"> | |
<input class="orange-button" type="submit" value="Simpan" name="save" /> | |
</div> | |
</form> | |
</div> | |
<!-- Option 1: Bootstrap Bundle with Popper --> | |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include("config.php"); | |
// cek apakah tombol daftar sudah diklik atau blum? | |
if(isset($_POST['save'])){ | |
// ambil data dari formulir | |
$nama = $_POST['nama']; | |
$nip = $_POST['nip']; | |
$alamat = $_POST['alamat']; | |
$phone = $_POST['phone']; | |
$jk = $_POST['gender']; | |
// buat query | |
$sql = "INSERT INTO students (nama, nip, alamat, phone, gender) VALUE ('$nama', '$nip','$alamat', '$phone', '$jk')"; | |
$query = mysqli_query($db, $sql); | |
// apakah query simpan berhasil? | |
if( $query ) { | |
// kalau berhasil alihkan ke halaman hone.php dengan status=sukses | |
header('Location: home.php?status=sukses'); | |
} else { | |
// kalau gagal alihkan ke halaman home.php dengan status=gagal | |
header('Location: home.php?status=gagal'); | |
} | |
} else { | |
die("Akses dilarang..."); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include("config.php"); | |
if( isset($_GET['id']) ){ | |
// ambil id dari query string | |
$id = $_GET['id']; | |
// buat query hapus | |
$sql = "DELETE FROM students WHERE id=$id"; | |
$query = mysqli_query($db, $sql); | |
// apakah query hapus berhasil? | |
if( $query ){ | |
header('Location: student_list.php'); | |
} else { | |
die("gagal menghapus..."); | |
} | |
} else { | |
die("akses dilarang..."); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include("config.php"); | |
// Initialize the session | |
session_start(); | |
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){ | |
header("Location: login.php"); | |
exit; | |
} | |
// kalau tidak ada id di query string | |
if( !isset($_GET['id']) ){ | |
header('Location: student_list.php'); | |
} | |
//ambil id dari query string | |
$id = $_GET['id']; | |
// buat query untuk ambil data dari database | |
$sql = "SELECT * FROM students 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>Edit Student - TSHS</title> | |
<meta charset="UTF-8"> | |
<meta name="author" content="Axel"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> | |
<style type="text/css"> | |
html, body { | |
margin: 0; | |
padding: 0; | |
} | |
.home-title { | |
color: #FF4B35; | |
margin-top: 3rem; | |
font-size: 3em; | |
font-weight: bold; | |
} | |
.student-add-container { | |
width: 100%; | |
padding: 0rem 12rem; | |
display: flex; | |
flex-direction: column; | |
align-items: center; | |
justify-content: center; | |
} | |
.login-form-container { | |
width: 60%; | |
display: flex; | |
flex-direction: column; | |
} | |
.orange-button { | |
background-color: #FE705F; | |
width: 100%; | |
text-align: center; | |
color: #fff; | |
border: none; | |
padding: 0.5rem 1rem; | |
border-radius: 5px; | |
font-size: 1rem; | |
cursor: pointer; | |
text-decoration: none; | |
} | |
.orange-button:hover { | |
background-color: #E46657; | |
color: #fff; | |
text-decoration: none; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="student-add-container"> | |
<h1 class="home-title">Edit Student Data</h1> | |
<form action="student_edit_control.php" class="login-form-container" method="post"> | |
<input type="hidden" name="id" value="<?php echo $siswa['id'] ?>" /> | |
<div class="mb-3 form-group"> | |
<label for="input-nama" class="form-label">Nama</label> | |
<input type="text" name="nama" class="form-control" id="input-nama" value="<?php echo $siswa['nama'] ?>"> | |
</div> | |
<div class="mb-3 form-group"> | |
<label for="input-nip" class="form-label">NIP</label> | |
<input type="text" name="nip" class="form-control" id="input-nip" value="<?php echo $siswa['nip'] ?>"> | |
</div> | |
<div class="form-group"> | |
<label for="input-alamat" class="form-label">Alamat</label> | |
<textarea class="form-control" name="alamat"><?php echo $siswa['alamat'] ?></textarea> | |
</div> | |
<div class="mb-3 form-group"> | |
<label for="input-phone" class="form-label">Phone</label> | |
<input type="phone" name="phone" class="form-control" id="input-phone" value="<?php echo $siswa['phone'] ?>"> | |
</div> | |
<?php $gender = $siswa['gender']; ?> | |
<div class="form-group"> | |
<label for="gender">Jenis Kelamin</label> | |
<select class="form-control" name="gender"> | |
<option <?php echo ($gender == 'Laki-laki') ? "selected": "" ?> value="Laki-laki">Laki-laki</option> | |
<option <?php echo ($gender == 'Perempuan') ? "selected": "" ?> value="Perempuan">Perempuan</option> | |
</select> | |
</div> | |
<div class="form-group"> | |
<input class="orange-button" type="submit" value="Simpan" name="update" /> | |
</div> | |
</form> | |
</div> | |
<!-- Option 1: Bootstrap Bundle with Popper --> | |
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | |
</body> | |
</html> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include("config.php"); | |
// cek apakah tombol simpan sudah diklik atau blum? | |
if(isset($_POST['update'])){ | |
// ambil data dari formulir | |
$id = $_POST['id']; | |
$nama = $_POST['nama']; | |
$nip = $_POST['nip']; | |
$alamat = $_POST['alamat']; | |
$phone = $_POST['phone']; | |
$jk = $_POST['gender']; | |
// buat query update | |
$sql = "UPDATE students SET nama='$nama', nip='$nip', alamat='$alamat', phone='$phone', gender='$jk' WHERE id=$id"; | |
$query = mysqli_query($db, $sql); | |
// apakah query update berhasil? | |
if( $query ) { | |
// kalau berhasil alihkan ke halaman student_list.php | |
header('Location: student_list.php'); | |
} else { | |
// kalau gagal tampilkan pesan | |
die("Gagal menyimpan perubahan..."); | |
} | |
} else { | |
die("Akses dilarang..."); | |
} | |
?> |
Comments
Post a Comment