<?php include('config.php'); ?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <title>Edit Barang</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <h2>Edit Barang</h2>
    <?php
    $id = $_GET['id'];
    $result = mysqli_query($conn, "SELECT * FROM barang WHERE id=$id");
    $data = mysqli_fetch_assoc($result);
    ?>
    <form action="" method="POST">
        Nama Barang: <input type="text" name="nama_barang" value="<?php echo $data['nama_barang']; ?>" required><br>
        Jenis Barang: <input type="text" name="jenis_barang" value="<?php echo $data['jenis_barang']; ?>" required><br>
        Harga: <input type="number" name="harga_barang" value="<?php echo $data['harga_barang']; ?>" required><br>
        Stok: <input type="number" name="stok_barang" value="<?php echo $data['stok_barang']; ?>" required><br>
        <button type="submit" name="submit">Update</button>
    </form>
    <?php
    if (isset($_POST['submit'])) {
        $nama_barang = $_POST['nama_barang'];
        $jenis_barang = $_POST['jenis_barang'];
        $harga_barang = $_POST['harga_barang'];
        $stok_barang = $_POST['stok_barang'];

        $query = "UPDATE barang SET nama_barang='$nama_barang', jenis_barang='$jenis_barang', harga_barang='$harga_barang', stok_barang='$stok_barang' WHERE id=$id";
        mysqli_query($conn, $query);
        header("Location: index.php");
    }
    ?>
</body>
</html>
