$max_size)
$errors[] = ‘Document must be under 5MB.’;
else {
$upload_dir = __DIR__ . ‘/uploads/’;
if (!is_dir($upload_dir)) mkdir($upload_dir, 0755, true);
$ext = pathinfo($_FILES[‘document’][‘name’], PATHINFO_EXTENSION);
$doc_filename = uniqid(‘doc_’, true) . ‘.’ . $ext;
$doc_path = $upload_dir . $doc_filename;
if (!move_uploaded_file($_FILES[‘document’][‘tmp_name’], $doc_path))
$errors[] = ‘Failed to upload document. Please try again.’;
}
} else {
$errors[] = ‘Please upload a document.’;
}
if (empty($errors)) {
try {
$pdo = new PDO(
‘mysql:host=’ . DB_HOST . ‘;port=’ . DB_PORT . ‘;dbname=’ . DB_NAME . ‘;charset=utf8mb4’,
DB_USER,
DB_PASS,
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
$stmt = $pdo->prepare(“SELECT id FROM otp_registrations WHERE email = ?”);
$stmt->execute([$email]);
if ($stmt->fetch()) {
$errors[] = ‘This email address is already registered.’;
} else {
$stmt = $pdo->prepare(”
INSERT INTO otp_registrations
(full_name, email, phone, position, blood_group, membership_validity, document_path)
VALUES (?, ?, ?, ?, ?, ?, ?)
“);
$stmt->execute([
$full_name,
$email,
$phone,
$position,
$blood,
$validity,
$doc_path
]);
$success = true;
}
} catch (PDOException $e) {
$errors[] = ‘Could not save your registration. Please try again later.’;
}
}
}
?>
Member Registration – OTP Qatar