prepare("SELECT address, phone1, phone2, email, map_embed_url FROM site_config WHERE id = 1"); $stmt->execute(); $siteConfig = $stmt->fetch(PDO::FETCH_ASSOC); // Sanitize site config data $siteConfig['address'] = htmlspecialchars($siteConfig['address'] ?? 'Vill And post Mudai, Mainpuri, Uttar Pradesh 205301'); $siteConfig['phone1'] = htmlspecialchars($siteConfig['phone1'] ?? '7454838285'); $siteConfig['phone2'] = htmlspecialchars($siteConfig['phone2'] ?? ''); $siteConfig['email'] = htmlspecialchars($siteConfig['email'] ?? 'official.ndfoundation@gmail.com'); $siteConfig['map_embed_url'] = htmlspecialchars($siteConfig['map_embed_url'] ?? ''); // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'submit_contact') { header('Content-Type: application/json'); if (!verifyCSRF($_POST['csrf_token'])) { echo json_encode(['success' => false, 'message' => 'Invalid CSRF token']); exit; } $name = sanitizeInput($_POST['name']); $mobile = sanitizeInput($_POST['mobile']); $email = sanitizeInput($_POST['email']); $topic = sanitizeInput($_POST['topic']); $description = sanitizeInput($_POST['description']); try { $stmt = $db->prepare("INSERT INTO contact_messages (name, mobile, email, topic, description, created_at, status) VALUES (?, ?, ?, ?, ?, NOW(), 'pending')"); $stmt->execute([$name, $mobile, $email, $topic, $description]); echo json_encode(['success' => true]); exit; } catch (PDOException $e) { logError('Contact form submission error: ' . $e->getMessage()); echo json_encode(['success' => false, 'message' => 'Failed to submit message. Please try again.']); exit; } } include 'header.php'; include 'navbar.php'; ?>