<?php
require 'koneksi.php';
$con = open_connection();

$id = $_GET['id'];

$data = mysqli_fetch_assoc(
    mysqli_query($con,
    "SELECT * FROM guru WHERE id_guru='$id'")
);

if(isset($_POST['update'])){

    $nama = $_POST['nama'];
    $nip = $_POST['nip'];
    $username = $_POST['username'];
    $password = $_POST['password'];
    $no_hp = $_POST['no_hp'];

    mysqli_query($con,"
        UPDATE guru SET
        nama='$nama',
        nip='$nip',
        username='$username',
        password='$password',
        no_hp='$no_hp'
        WHERE id_guru='$id'
    ");

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

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

<div class="container mt-4">

<h2>Edit Guru</h2>

<form method="POST">

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

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

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

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

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

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

</form>

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