<?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 calon_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 Pendaftaran Siswa Baru | SMK Coding</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<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://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
</head>
<body>
<header>
<center><h3>Formulir Edit Data Siswa</h3></center>
</header>
<div class="container">
<form action="proses-edit.php" method="POST">
<fieldset>
<input type="hidden" name="id" value="<?=$siswa[\'id\']?>" />
<div class="mb-3">
<label for="nama" class="form-label">Nama: </label>
<input type="text" name="nama" placeholder="nama lengkap" class="form-control" value="<?=$siswa[\'nama\'];?>"/>
</div>
<p>
<label for="alamat" class="form-label">Alamat: </label>
<textarea name="alamat" class="form-control" placeholder="Masukkan Alamat"><?=$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" <?=(($jk==\'laki-laki\')?"checked":"")?>> Laki-laki</label>
<label><input type="radio" name="jenis_kelamin" value="perempuan" <?=(($jk==\'perempuan\')?"checked":"")?>> Perempuan</label>
</p>
<p>
<label for="agama">Agama: </label>
<?php $agama = $siswa[\'agama\']; ?>
<select name="agama">
<option <?=(($agama == \'Islam\') ? "selected": "")?>>Islam</option>
<option <?=(($agama == \'Kristen\') ? "selected": "")?>>Kristen</option>
<option <?=(($agama == \'Hindu\') ? "selected": "")?>>Hindu</option>
<option <?=(($agama == \'Budha\') ? "selected": "")?>>Budha</option>
<option <?=(($agama == \'Atheis\') ? "selected": "")?>>Atheis</option>
</select>
</p>
<p>
<label for="sekolah_asal">Sekolah Asal: </label>
<input type="text" name="sekolah_asal" placeholder="nama sekolah" value="<?=$siswa[\'sekolah_asal\']?>" />
</p>
<center>
<input type="submit" value="Simpan" name="submit" class="btn btn-success" />
<a href="list-siswa.php" class="btn btn-danger">Batal</a>
</center>
</fieldset>
</form>
</div>
</body>
</html>