9) {
$pars[] = 0;
} else {
$par_value = filter_input(INPUT_POST, 'par_hole_' . $i, FILTER_VALIDATE_INT);
if ($par_value === false || $par_value < 1 || $par_value > 7) {
$error = "Invalid par value for hole " . $i . ". Please enter a number between 1 and 7.";
$isValid = false;
break;
}
$pars[] = $par_value;
}
}
}
if ($isValid) {
try {
$pdo = db();
$sql = "INSERT INTO courses (name, hole_count, tournament_date, par_hole_1, par_hole_2, par_hole_3, par_hole_4, par_hole_5, par_hole_6, par_hole_7, par_hole_8, par_hole_9, par_hole_10, par_hole_11, par_hole_12, par_hole_13, par_hole_14, par_hole_15, par_hole_16, par_hole_17, par_hole_18) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$params = array_merge([$courseName, $hole_count, $tournament_date], $pars);
$stmt->execute($params);
$_SESSION['success_message'] = "Course '{$courseName}' added successfully!";
header("Location: admin.php");
exit;
} catch (PDOException $e) {
$error = "Database error: " . $e->getMessage();
}
}
}
// Fetch existing courses
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, name, hole_count, tournament_date FROM courses ORDER BY name");
$courses = $stmt->fetchAll();
} catch (PDOException $e) {
$courses = [];
$error = "Could not fetch courses: " . $e->getMessage();
}
// Fetch players with their team names
try {
$pdo = db();
$stmt = $pdo->query("
SELECT p.id, p.name, p.email, p.high_school_year, p.season_year, t.name as team_name
FROM players p
LEFT JOIN teams t ON p.team_id = t.id
ORDER BY p.name
");
$players = $stmt->fetchAll();
} catch (PDOException $e) {
$players = [];
$error = "Could not fetch players: " . $e->getMessage();
}
?>
Admin Dashboard - Golf Tournament
Admin Dashboard
' . htmlspecialchars($_SESSION['success_message']) . '
';
unset($_SESSION['success_message']);
}
?>
-
-
-
Existing Courses
| Course Name |
Holes |
Tournament Date |
Action |
| No courses found. |
|
|
|
|
...