diff --git a/add_player.php b/add_player.php new file mode 100644 index 0000000..f56cf27 --- /dev/null +++ b/add_player.php @@ -0,0 +1,44 @@ +prepare("SELECT id FROM players WHERE email = ?"); + $stmt->execute([$player_email]); + $player = $stmt->fetch(); + + if ($player) { + $player_id = $player['id']; + } else { + // Insert new player + $stmt = $pdo->prepare("INSERT INTO players (name, email, high_school_year, season_year) VALUES (?, ?, ?, ?)"); + $stmt->execute([$player_name, $player_email, $high_school_year, $season_year]); + $player_id = $pdo->lastInsertId(); + } + + // Add player to team + $stmt = $pdo->prepare("INSERT INTO team_members (team_id, player_id) VALUES (?, ?)"); + $stmt->execute([$team_id, $player_id]); + + $_SESSION['success_message'] = 'Player added successfully!'; + } catch (PDOException $e) { + $_SESSION['error_message'] = 'Error adding player: ' . $e->getMessage(); + } + } + + header('Location: coach.php'); + exit; +} +?> \ No newline at end of file diff --git a/add_score.php b/add_score.php index 89df036..778d2a9 100644 --- a/add_score.php +++ b/add_score.php @@ -1,14 +1,19 @@ query("SELECT id, name FROM courses ORDER BY name"); $courses = $stmt->fetchAll(); + + $stmt = $pdo->query("SELECT p.id, p.player_name, t.team_name FROM players p JOIN teams t ON p.team_id = t.id ORDER BY t.team_name, p.player_name"); + $players = $stmt->fetchAll(); } catch (PDOException $e) { - $courses = []; - // Silently fail, the JS will handle the empty state + // If something goes wrong, we'll have empty arrays. + // For debugging, you might want to log the error: + // error_log($e->getMessage()); } ?> @@ -50,12 +55,27 @@ try {
| Player | -Course | -Score | -Date | -Action | +Name | +High School Year | +Season Year | +Actions | |
|---|---|---|---|---|---|---|---|---|---|
| = htmlspecialchars($score['player_name']) ?> | -= htmlspecialchars($score['course_name']) ?> | -= htmlspecialchars($score['total_score']) ?> | -= date('Y-m-d', strtotime($score['played_at'])) ?> | -Edit | += htmlspecialchars($player['name']) ?> | += htmlspecialchars($player['email']) ?> | += htmlspecialchars($player['high_school_year']) ?> | += htmlspecialchars($player['season_year']) ?> | ++ Edit + Delete + |
No scores recorded for this team yet.
+No players in this team yet.
+ +