<?php
require_once '../config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $result_date = $_POST['result_date'];
    $game = $_POST['game'];
    $result_number = $_POST['result_number'];

    $sql = "INSERT INTO results (result_date, game, result_number) VALUES (?, ?, ?)";
    if ($stmt = mysqli_prepare($link, $sql)) {
        mysqli_stmt_bind_param($stmt, 'sss', $result_date, $game, $result_number);
        if (mysqli_stmt_execute($stmt)) {
            echo '<div class="success" style="max-width:600px;margin:20px auto;">Result added successfully!</div>';
        } else {
            echo '<div class="error" style="max-width:600px;margin:20px auto;">Error adding result.</div>';
        }
        mysqli_stmt_close($stmt);
    } else {
        echo '<div class="error" style="max-width:600px;margin:20px auto;">Database error.</div>';
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Add Results</title>
    <link rel="stylesheet" href="../style.css">
</head>
<body>
     <div class="wrapper" style="max-width:600px; margin:40px auto;">
        <h2>Add Results</h2>
        <form action="add-results.php" method="post">
                <label for="result_date">Date</label>
                <input type="date" name="result_date" class="styled-input" required>
                <label for="game">Game</label>
                <select name="game" class="styled-input" required>
                    <option value="disawar">Disawar</option>
                    <option value="dl_bazaar">DL Bazaar</option>
                    <option value="shri_ganesh">Shri Ganesh</option>
                    <option value="faridabad">Faridabad</option>
                    <option value="ghaziabad">Ghaziabad</option>
                    <option value="radhey_radhey">Radhey Radhey</option>
                    <option value="gali">Gali</option>
                </select>
          
           
                <label for="result_number">Result Number</label>
                <input type="text" name="result_number" class="styled-input" required>
            <button class="cta" type="submit">Add Results</button>
        </form>
    </div>
</body>
</html>