<?php
$ambil = $koneksi->query("SELECT * FROM gejala WHERE idgejala='$_GET[id]'");
$row = $ambil->fetch_assoc();
?>

<div class="row">
    <div class="col-md-12 mb-4">
        <div class="card shadow mb-4">
            <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                <h6 class="m-0 font-weight-bold  ">Ubah Gejala</h6>
            </div>
            <div class="card-body">
                <form method="post" enctype="multipart/form-data">
                    <div class="form-group">
                        <label>Kode Gejala</label>
                        <input type="text" class="form-control" name="kodegejala" value="<?php echo $row['kodegejala']; ?>" required>
                    </div>
                    <div class="form-group">
                        <label>Nama Gejala</label>
                        <textarea type="text" class="form-control" name="gejala" required><?php echo $row['gejala']; ?></textarea>
                    </div>
                    
                    <button class="btn btn-primary" name="ubah"><i class="glyphicon glyphicon-saved"></i>Simpan</button>
                </form>
            </div>
        </div>
    </div>
</div>

<?php
if (isset($_POST['ubah'])) {
    // Memperbarui kondisi berdasarkan input yang ada pada formulir
    $gejala = mysqli_real_escape_string($koneksi, $_POST['gejala']);
    $kodegejala = mysqli_real_escape_string($koneksi, $_POST['kodegejala']);

    $koneksi->query("UPDATE gejala SET gejala='$gejala', kodegejala='$kodegejala' WHERE idgejala='$_GET[id]'");

    echo "<script>alert('Data Berhasil Diubah');</script>";
    echo "<script>location='index.php?halaman=gejaladaftar';</script>";
}
?>