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, 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); $stmt->execute(array_merge([$courseName], $pars)); $_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 FROM courses ORDER BY name"); $courses = $stmt->fetchAll(); } catch (PDOException $e) { $courses = []; $error = "Could not fetch courses: " . $e->getMessage(); } ?>
| Course Name | Action |
|---|---|
| No courses found. | |