prepare('SELECT * FROM communities WHERE id = ?'); $stmt->execute([$community_id]); $community = $stmt->fetch(); if (!$community) { echo "Community not found."; exit; } // Fetch user role $stmt = $pdo->prepare('SELECT role FROM users WHERE id = ?'); $stmt->execute([$user_id]); $user_role = $stmt->fetchColumn(); // Handle event creation $errors = []; $title = $description = $start_time = $end_time = $location = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $title = trim($_POST['title'] ?? ''); $description = trim($_POST['description'] ?? ''); $start_time = $_POST['start_time'] ?? ''; $end_time = $_POST['end_time'] ?? ''; $location = trim($_POST['location'] ?? ''); if (empty($title)) { $errors[] = 'Title is required.'; } if (empty($description)) { $errors[] = 'Description is required.'; } if (empty($start_time)) { $errors[] = 'Start time is required.'; } if (empty($end_time)) { $errors[] = 'End time is required.'; } if (empty($location)) { $errors[] = 'Location is required.'; } if (strtotime($start_time) >= strtotime($end_time)) { $errors[] = 'End time must be after start time.'; } if (empty($errors)) { $stmt = $pdo->prepare('INSERT INTO events (community_id, user_id, title, description, start_time, end_time, location) VALUES (?, ?, ?, ?, ?, ?, ?)'); if ($stmt->execute([$community_id, $user_id, $title, $description, $start_time, $end_time, $location])) { header("Location: events.php?community_id=$community_id"); exit; } else { $errors[] = 'Failed to create event. Please try again.'; } } } // Fetch events for the community $stmt = $pdo->prepare('SELECT e.*, u.name as user_name FROM events e JOIN users u ON e.user_id = u.id WHERE e.community_id = ? ORDER BY e.start_time DESC'); $stmt->execute([$community_id]); $events = $stmt->fetchAll(); ?> <?php echo htmlspecialchars($community['name']); ?> Events - Community Hub

Events in

Stay up-to-date with the latest happenings.

Create a New Event

Upcoming Events

No events yet. Be the first to create one!