prepare("SELECT id FROM applications WHERE event_id = ? AND user_id = ?"); $stmt->execute([$event_id, $user_id]); if ($stmt->fetch()) { $_SESSION['flash_message'] = [ 'type' => 'warning', 'message' => 'You have already applied to this event.' ]; header('Location: index.php#events'); exit(); } // 4. Insert new application $stmt = $pdo->prepare("INSERT INTO applications (event_id, user_id, status) VALUES (?, ?, 'awaiting_proof')"); $stmt->execute([$event_id, $user_id]); $_SESSION['flash_message'] = [ 'type' => 'success', 'message' => 'You have successfully applied! Please upload your proof in the dashboard.' ]; } catch (PDOException $e) { // error_log($e->getMessage()); // Log error for debugging $_SESSION['flash_message'] = [ 'type' => 'danger', 'message' => 'A database error occurred. Please try again.' ]; } // 5. Redirect back to the events section header('Location: index.php#events'); exit();