28 lines
1.0 KiB
PHP
28 lines
1.0 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
echo json_encode(['success' => false, 'error' => 'Invalid request method.']);
|
|
exit;
|
|
}
|
|
|
|
$firstName = trim($_POST['first_name'] ?? '');
|
|
$lastName = trim($_POST['last_name'] ?? '');
|
|
$rank = trim($_POST['clergy_rank'] ?? '');
|
|
$metropolis = trim($_POST['metropolis_name'] ?? '');
|
|
$email = trim($_POST['email'] ?? '');
|
|
|
|
if (empty($firstName) || empty($lastName) || empty($rank) || empty($metropolis)) {
|
|
echo json_encode(['success' => false, 'error' => 'All required fields must be filled.']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$stmt = db()->prepare("INSERT INTO clergy (first_name, last_name, clergy_rank, metropolis_name, email) VALUES (?, ?, ?, ?, ?)");
|
|
$stmt->execute([$firstName, $lastName, $rank, $metropolis, $email]);
|
|
echo json_encode(['success' => true]);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'error' => 'Database error: ' . $e->getMessage()]);
|
|
}
|