<?php
require 'koneksi.php';

$con = open_connection();

$id = $_GET['id'];

$query = mysqli_query($con, "SELECT * FROM murid WHERE id_murid='$id'");
$data = mysqli_fetch_assoc($query);

if(isset($_POST['update']))
{
    $nama = $_POST['nama'];
    $nisn = $_POST['nisn'];
    $kode_kelas = $_POST['kode_kelas'];

    mysqli_query($con,
    "UPDATE murid SET
    nama='$nama',
    nisn='$nisn',
    kode_kelas='$kode_kelas'
    WHERE id_murid='$id'");

    catat_log($con, "Data murid diperbarui: " . $nama, "murid");

    header("Location: murid.php");
}
?>
<?php require 'header.php';?>

<div class="container mt-4">

    <h2>Edit Data Murid</h2>

    <form method="POST">

        <div class="mb-3">
            <label>Nama</label>
            <input type="text"
                name="nama"
                class="form-control"
                value="<?= $data['nama']; ?>"
                required>
        </div>

        <div class="mb-3">
            <label>NISN</label>
            <input type="text"
                name="nisn"
                class="form-control"
                value="<?= $data['nisn']; ?>"
                required>
        </div>

        <div class="mb-3">
            <label>Kode Kelas</label>
            <input type="text"
                name="kode_kelas"
                class="form-control"
                value="<?= $data['kode_kelas']; ?>"
                required>
        </div>

        <button type="submit"
                name="update"
                class="btn btn-success">
            Update
        </button>

        <a href="murid.php" class="btn btn-secondary">
            Kembali
        </a>

    </form>

</div>
<?php include 'footer.php';?>