How can a PHP form be utilized to input and store game results for multiple teams and matches?

To input and store game results for multiple teams and matches using a PHP form, you can create a form with fields for team names, match results, and dates. Upon submission, the PHP script can store the data in a database table, allowing for easy retrieval and management of game results.

<?php
// Connect to database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "game_results";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Process form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $team1 = $_POST['team1'];
    $team2 = $_POST['team2'];
    $result = $_POST['result'];
    $date = $_POST['date'];

    // Insert data into database
    $sql = "INSERT INTO game_results (team1, team2, result, date) VALUES ('$team1', '$team2', '$result', '$date')";
    
    if ($conn->query($sql) === TRUE) {
        echo "Game results stored successfully!";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
}

// Close database connection
$conn->close();
?>