<?php
$id = $_GET['id'];
$ambil = $koneksi->query("SELECT * FROM interpretasi_fuzzy WHERE id_fuzzy='$id'");
$data = $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">
                <h6 class="m-0 font-weight-bold">Ubah Interpretasi Fuzzy</h6>
            </div>
            <div class="card-body">
                <form method="post">
                    <div class="form-group">
                        <label>Kategori</label>
                        <input type="text" class="form-control" name="kategori" value="<?php echo $data['kategori']; ?>" required>
                    </div>
                    <div class="form-group">
                        <label>Nilai Interpretasi</label>
                        <input type="number" step="0.1" class="form-control" name="nilai_interpretasi" value="<?php echo $data['nilai_interpretasi']; ?>" required>
                    </div>
                    <button type="submit" class="btn btn-primary" name="update">Ubah</button>
                </form>
            </div>
        </div>
    </div>
</div>

<?php
if (isset($_POST['update'])) {
    $kategori = mysqli_real_escape_string($koneksi, $_POST['kategori']);
    $nilai_interpretasi = mysqli_real_escape_string($koneksi, $_POST['nilai_interpretasi']);

    $koneksi->query("UPDATE interpretasi_fuzzy SET kategori='$kategori', nilai_interpretasi='$nilai_interpretasi' WHERE id_fuzzy='$id'");

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