prepare($sql); $stmt->execute([$email]); if ($stmt->fetch()) { die('Email already exists.'); } // Insert into drivers table $password_hash = password_hash($password, PASSWORD_BCRYPT); $sql = "INSERT INTO drivers (full_name, email, password_hash, phone_number, vehicle_details, approval_status) VALUES (?, ?, ?, ?, ?, 'pending')"; $stmt = $pdo->prepare($sql); if ($stmt->execute([$full_name, $email, $password_hash, $phone_number, $vehicle_details])) { // Send email notification to admins require_once __DIR__ . '/mail/MailService.php'; $stmt_emails = $pdo->prepare("SELECT email FROM email_recipients WHERE form_type = ?"); $stmt_emails->execute(['driver_signup']); $recipients = $stmt_emails->fetchAll(PDO::FETCH_COLUMN); if (!empty($recipients)) { $subject = 'New Driver Signup: ' . $full_name; $html_content = "

A new driver has signed up and is awaiting approval.

" . "

Name: {$full_name}

" . "

Email: {$email}

" . "

Phone: {$phone_number}

" . "

Vehicle: {$vehicle_details}

" . "

Please visit the admin panel to review and approve the application.

"; $text_content = "A new driver has signed up and is awaiting approval.\n\n" . "Name: {$full_name}\n" . "Email: {$email}\n" . "Phone: {$phone_number}\n" . "Vehicle: {$vehicle_details}\n\n" . "Please visit the admin panel to review and approve the application."; MailService::sendMail($recipients, $subject, $html_content, $text_content); } // Redirect to a pending approval page header("Location: driver_pending_approval.php"); exit; } else { die("Error: Could not execute the query."); } } catch (PDOException $e) { die("Could not connect to the database: " . $e->getMessage()); } } ?>