<?php
include 'config.php'; // koneksi database

// ambil data
$name = $_POST['name'];
$draw_number = $_POST['draw_number'];
$first = $_POST['first_prize'];
$second = $_POST['second_prize'];
$third = $_POST['third_prize'];
$starter = $_POST['starter_prize'];
$consolation = $_POST['consolation_prize'];
$start_time = $_POST['result_time_start'];
$end_time = $_POST['result_time_end'];
$draw_date = $_POST['draw_date'];

// parsing date
$date_parts = explode("-", $draw_date);
$year = $date_parts[0];
$month = date("F", mktime(0, 0, 0, $date_parts[1], 10)); // Nama bulan
$day = (int)$date_parts[2];

$sql = "INSERT INTO pasaran (name, draw_number, first_prize, second_prize, third_prize, starter_prize, consolation_prize, result_time_start, result_time_end, draw_date, month, day, year)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

$stmt = $conn->prepare($sql);
$stmt->bind_param("sssssssssssis", $name, $draw_number, $first, $second, $third, $starter, $consolation, $start_time, $end_time, $draw_date, $month, $day, $year);
$stmt->execute();

header("Location: admin.php");
