prepare('SELECT id FROM users WHERE username = ? OR email = ?'); $stmt->execute([$username, $email]); if ($stmt->fetch()) { $error = 'Username or email already exists.'; } else { // Insert new user $hashed_password = password_hash($password, PASSWORD_DEFAULT); $stmt = $db->prepare('INSERT INTO users (username, email, password, role) VALUES (?, ?, ?, ?)'); $stmt->execute([$username, $email, $hashed_password, $role]); $success = 'Registration successful! You can now login.'; } } catch (PDOException $e) { $error = 'Database error: ' . $e->getMessage(); } } } ?>

Register