Already have an account? Login here.
prepare("SELECT * FROM users WHERE username = :username OR email = :email"); $stmt->execute([':username' => $username, ':email' => $email]); if ($stmt->fetch()) { $error_message = "Username or email already exists."; } else { // Insert new user $password_hash = password_hash($password, PASSWORD_DEFAULT); $stmt = $pdo->prepare("INSERT INTO users (username, email, password) VALUES (:username, :email, :password)"); $stmt->execute([ ':username' => $username, ':email' => $email, ':password' => $password_hash ]); $success_message = "Registration successful! You can now log in."; // Optional: Send a welcome email // MailService::sendMail($email, "Welcome to Our Service!", "Thank you for registering.", "Thank you for registering."); } } catch (PDOException $e) { // In a real app, you would log this error, not show it to the user $error_message = "Database error: " . $e->getMessage(); } } } ?>
Already have an account? Login here.