<?php
include "../koneksi.php";

$id = $_POST['id'];
$draw_type = $_POST['draw_type'];
$tanggal = $_POST['tanggal'];
$winner_prize = $_POST['winner_prize'];
$prize2 = $_POST['prize2'];
$prize3 = $_POST['prize3'];
$draw_id = $_POST['draw_id'];

// Update ke tabel utama: result_lengkap
$proses = mysqli_query($koneksi, "UPDATE result_lengkap SET 
    draw_type = '$draw_type', 
    tanggal = '$tanggal', 
    winner_prize = '$winner_prize', 
    prize2 = '$prize2', 
    prize3 = '$prize3' 
    WHERE draw_id = '$draw_id'");

if ($proses) {
    // Karena hanya ada talaga, langsung update tabel result_talaga
    $update_talaga = mysqli_query($koneksi, "UPDATE result_talaga SET 
        tanggal = '$tanggal', 
        winner_prize = '$winner_prize', 
        prize2 = '$prize2', 
        prize3 = '$prize3' 
        WHERE draw_id = '$draw_id'");

    if ($update_talaga) {
        header("Location: result.php?alert=berhasil");
        exit();
    } else {
        echo "Gagal memperbarui tabel result_talaga.<br>Error: " . mysqli_error($koneksi);
    }
} else {
    echo "Gagal memperbarui tabel result_lengkap.<br>Error: " . mysqli_error($koneksi);
}

// Tutup koneksi
mysqli_close($koneksi);
