index.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // error reporting
  3. error_reporting(E_ALL);
  4. // Include the external configuration file
  5. require_once '../config.php';
  6. try {
  7. // Use the settings from config.php for the PDO connection
  8. $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
  9. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  10. } catch (PDOException $e) {
  11. echo 'Connection failed: ' . $e->getMessage();
  12. exit;
  13. }
  14. // Query to fetch activities and their corresponding names
  15. $query = "
  16. SELECT a.activityID, an.activityName
  17. FROM activities a
  18. JOIN activity_names an ON a.activityID = an.activityID
  19. ";
  20. // Execute the query and fetch the results
  21. $stmt = $pdo->query($query);
  22. $activities = $stmt->fetchAll(PDO::FETCH_ASSOC);
  23. // If no activities found
  24. if (!$activities) {
  25. echo "No activities found.";
  26. exit;
  27. }
  28. ?>
  29. <!DOCTYPE html>
  30. <html lang="en">
  31. <head>
  32. <meta charset="UTF-8">
  33. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  34. <title>Activity Selection</title>
  35. <style>
  36. body {
  37. font-family: Arial, sans-serif;
  38. padding: 20px;
  39. }
  40. .category-item {
  41. margin: 5px 0;
  42. }
  43. .category-item input {
  44. margin-right: 10px;
  45. }
  46. </style>
  47. </head>
  48. <body>
  49. <h1>Select Activities</h1>
  50. <form action="submit_activities.php" method="GET">
  51. <?php foreach ($activities as $activity): ?>
  52. <div class="activity-item">
  53. <input type="checkbox" name="activity_ids" value="<?php echo htmlspecialchars($activity['activityID']); ?>">
  54. <label for="category_<?php echo htmlspecialchars($activity['activityID']); ?>">
  55. <?php echo htmlspecialchars($activity['activityName']); ?>
  56. </label>
  57. </div>
  58. <?php endforeach; ?>
  59. <br>
  60. <button type="submit">Pack it in!</button>
  61. </form>
  62. </body>
  63. </html>