<?php
$countries = $conn->query("SELECT * FROM countries");

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_league'])) {
    $league_name = $_POST['league_name'];
    $country_id = $_POST['country_id'];
    $stmt = $conn->prepare("INSERT INTO leagues (name, country_id) VALUES (?, ?)");
    $stmt->bind_param("si", $league_name, $country_id);
    $stmt->execute();
    echo "League '$league_name' added successfully!";
}
?>

<form method="POST">
    <input type="text" name="league_name" placeholder="League Name" required>
    <select name="country_id" required>
        <option value="">Select Country</option>
        <?php while ($row = $countries->fetch_assoc()): ?>
            <option value="<?= $row['id'] ?>"><?= $row['name'] ?></option>
        <?php endwhile; ?>
    </select>
    <button type="submit" name="add_league">Add League</button>
</form>
