<?
php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$connection = new mysqli('localhost', 'root', '', 'sports_cars_db');
if ($connection->connect_error) {
die("Connection failed: " . $connection->connect_error);
}
if (isset($_POST['name']) && isset($_POST['country']) &&
isset($_POST['foundedYear'])) {
$name = $_POST['name'];
$country = $_POST['country'];
$foundedYear = $_POST['foundedYear'];
$connection->query("INSERT INTO FootballClubs (Name, Country, FoundedYear)
VALUES ('$name', '$country', '$foundedYear')");
} elseif (isset($_POST['name']) && isset($_POST['position']) &&
isset($_POST['clubID'])) {
$name = $_POST['name'];
$position = $_POST['position'];
$clubID = $_POST['clubID'];
$connection->query("INSERT INTO FootballPlayers (Name, Position, ClubID)
VALUES ('$name', '$position', '$clubID')");
} elseif (isset($_POST['name']) && isset($_POST['location']) &&
isset($_POST['capacity']) && isset($_POST['clubID'])) {
$name = $_POST['name'];
$location = $_POST['location'];
$capacity = $_POST['capacity'];
$clubID = $_POST['clubID'];
$connection->query("INSERT INTO Stadiums (Name, Location, Capacity, ClubID)
VALUES ('$name', '$location', '$capacity', '$clubID')");
} elseif (isset($_POST['lista'])) {
$lista = $_POST['lista'];
switch ($lista) {
case 'FootballClubs':
$result = $connection->query("SELECT * FROM FootballClubs");
while ($row = $result->fetch_assoc()) {
echo "Name: " . $row['Name'] . " | Country: " . $row['Country']
. " | Founded Year: " . $row['FoundedYear'] . "<br>";
}
break;
case 'FootballPlayers':
$result = $connection->query("SELECT * FROM FootballPlayers");
while ($row = $result->fetch_assoc()) {
echo "Name: " . $row['Name'] . " | Position: " .
$row['Position'] . " | Club ID: " . $row['ClubID'] . "<br>";
}
break;
case 'Stadiums':
$result = $connection->query("SELECT * FROM Stadiums");
while ($row = $result->fetch_assoc()) {
echo "Name: " . $row['Name'] . " | Location: " .
$row['Location'] . " | Capacity: " . $row['Capacity'] . " | Club ID: " .
$row['ClubID'] . "<br>";
}
break;
default:
echo "Invalid list selected.";
}
}
$connection->close();
}
?>