Edit attendee #
Update registration details safely. Changes here affect the admin table, CSV export, and registration analytics.
query('SELECT id, title FROM webinars ORDER BY scheduled_at DESC, id DESC')->fetchAll(PDO::FETCH_ASSOC); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $webinarId = max(1, (int) ($_POST['webinar_id'] ?? 1)); $firstName = trim((string) ($_POST['first_name'] ?? '')); $lastName = trim((string) ($_POST['last_name'] ?? '')); $email = strtolower(trim((string) ($_POST['email'] ?? ''))); $company = trim((string) ($_POST['company'] ?? '')); $timezone = trim((string) ($_POST['timezone'] ?? '')); $howDidYouHear = trim((string) ($_POST['how_did_you_hear'] ?? '')); $consented = !empty($_POST['consented']) ? 1 : 0; if ($firstName === '' || $lastName === '') { throw new RuntimeException('First name and last name are required.'); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new RuntimeException('Enter a valid email address.'); } if ($timezone !== '' && !in_array($timezone, timezone_identifiers_list(), true)) { throw new RuntimeException('Timezone must be a valid IANA timezone, for example Europe/Berlin or America/New_York.'); } $webinarCheck = $pdo->prepare('SELECT COUNT(*) FROM webinars WHERE id = ?'); $webinarCheck->execute([$webinarId]); if ((int) $webinarCheck->fetchColumn() === 0) { throw new RuntimeException('Selected webinar was not found.'); } $update = $pdo->prepare('UPDATE attendees SET webinar_id = ?, first_name = ?, last_name = ?, email = ?, company = ?, timezone = ?, how_did_you_hear = ?, consented = ? WHERE id = ?'); $update->execute([$webinarId, $firstName, $lastName, $email, $company !== '' ? $company : null, $timezone !== '' ? $timezone : null, $howDidYouHear !== '' ? $howDidYouHear : null, $consented, $id]); admin_set_flash('Attendee #' . $id . ' was updated successfully.'); header('Location: admin.php'); exit; } $stmt = $pdo->prepare('SELECT * FROM attendees WHERE id = ? LIMIT 1'); $stmt->execute([$id]); $attendee = $stmt->fetch(PDO::FETCH_ASSOC); if (!$attendee) { admin_set_flash('Attendee not found.'); header('Location: admin.php'); exit; } } catch (RuntimeException $e) { admin_set_flash($e->getMessage()); header('Location: edit_attendee.php?id=' . urlencode((string) $id)); exit; } catch (PDOException $e) { error_log('Edit attendee error: ' . $e->getMessage()); admin_set_flash('Unable to load or save attendee changes right now.'); header('Location: admin.php'); exit; } $message = admin_get_flash(); ?>
Update registration details safely. Changes here affect the admin table, CSV export, and registration analytics.