<?php
include 'config.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $id = $_POST['id'];
    $update = mysqli_query($conn, "UPDATE lottery_results SET
        generate_time_2nd = '{$_POST['generate_time_2nd']}',
        generate_time_3rd = '{$_POST['generate_time_3rd']}',
        generate_time_starter = '{$_POST['generate_time_starter']}',
        generate_time_consolation = '{$_POST['generate_time_consolation']}'
        WHERE id = $id");

    echo $update ? "Update berhasil" : "Gagal update";
}

$result = mysqli_query($conn, "SELECT * FROM lottery_results ORDER BY id DESC LIMIT 1");
$data = mysqli_fetch_assoc($result);
?>

<h2>Set Waktu Prize</h2>
<form method="POST">
    <input type="hidden" name="id" value="<?= $data['id'] ?>">
    2nd Prize Time: <input type="time" name="generate_time_2nd" value="<?= $data['generate_time_2nd'] ?>"><br>
    3rd Prize Time: <input type="time" name="generate_time_3rd" value="<?= $data['generate_time_3rd'] ?>"><br>
    Starter Prize Time: <input type="time" name="generate_time_starter" value="<?= $data['generate_time_starter'] ?>"><br>
    Consolation Prize Time: <input type="time" name="generate_time_consolation" value="<?= $data['generate_time_consolation'] ?>"><br>
    <button type="submit">Simpan</button>
</form>
