Events in
Create a New Event
Upcoming Events
No events yet. Be the first to create one!
Location:
Created by:
prepare('SELECT * FROM communities WHERE id = ?'); $stmt->execute([$community_id]); $community = $stmt->fetch(); if (!$community) { header('Location: communities.php'); exit; } // Handle new event form submission $title = $description = $start_time = $end_time = $location = ''; $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $title = trim($_POST['title'] ?? ''); $description = trim($_POST['description'] ?? ''); $start_time = trim($_POST['start_time'] ?? ''); $end_time = trim($_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 (empty($errors)) { try { $stmt = $pdo->prepare('INSERT INTO events (community_id, user_id, title, description, start_time, end_time, location) VALUES (?, ?, ?, ?, ?, ?, ?)'); $stmt->execute([$community_id, $user_id, $title, $description, $start_time, $end_time, $location]); header('Location: events.php?community_id=' . $community_id); exit; } catch (PDOException $e) { $errors[] = 'Database error: ' . $e->getMessage(); } } } // Fetch events $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(); ?>
No events yet. Be the first to create one!
Location:
Created by: