prepare("SELECT id FROM users WHERE username = ?"); $st->execute([$username]); if ($st->fetch()) { $error = 'That username is already taken. Please choose another.'; } else { $dn = $displayName ?: $username; $hash = password_hash($password, PASSWORD_DEFAULT); $db->prepare("INSERT INTO users (username, password_hash, display_name) VALUES (?,?,?)") ->execute([$username, $hash, $dn]); $newId = (int)$db->lastInsertId(); // Give them a default account to get started $db->prepare("INSERT INTO accounts (user_id, name, currency) VALUES (?,?,?)") ->execute([$newId, 'Main Account', 'GBP']); // Auto-login $_SESSION['user'] = [ 'id' => $newId, 'username' => $username, 'display_name' => $dn, 'is_admin' => 0, ]; header('Location: index.php'); exit; } } catch (Exception $e) { $error = 'Registration failed. Please try again.'; } } } } ?> Register · <?= htmlspecialchars($siteName) ?>

Create your free account

Registration is currently disabled.
Please contact the site administrator.
3–30 characters · letters, numbers, underscores