38468-vm/register.php
Flatlogic Bot f65de53240 sadiq
2026-02-16 05:06:25 +00:00

93 lines
4.5 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
$error = '';
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = htmlspecialchars($_POST['name'] ?? '');
$email = htmlspecialchars($_POST['email'] ?? '');
$password = $_POST['password'] ?? '';
$confirm_password = $_POST['confirm_password'] ?? '';
if (empty($name) || empty($email) || empty($password)) {
$error = 'Please fill in all required fields.';
} elseif ($password !== $confirm_password) {
$error = 'Passwords do not match.';
} elseif (strlen($password) < 8) {
$error = 'Password must be at least 8 characters long.';
} else {
try {
// Check if email already exists
$stmt = db()->prepare("SELECT id FROM users WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$error = 'This email is already registered.';
} else {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = db()->prepare("INSERT INTO users (name, email, password) VALUES (?, ?, ?)");
$stmt->execute([$name, $email, $hashed_password]);
$success = 'Account created successfully! You can now <a href="login.php" style="color: var(--accent-gold);">login</a>.';
}
} catch (PDOException $e) {
$error = 'An error occurred. Please try again later.';
}
}
}
include 'includes/header.php';
?>
<main class="container mt-4" style="min-height: 70vh; display: flex; align-items: center; justify-content: center;">
<div style="width: 100%; max-width: 450px;">
<div class="glass-card">
<h2 class="text-center mb-4">Create Account</h2>
<p class="text-center mb-4" style="color: var(--text-muted);">Join the premium car marketplace in Afghanistan</p>
<?php if ($error): ?>
<div style="background: rgba(220, 53, 69, 0.2); border: 1px solid #dc3545; color: #dc3545; padding: 15px; border-radius: var(--radius-md); margin-bottom: 20px;">
<?php echo $error; ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div style="background: rgba(40, 167, 69, 0.2); border: 1px solid #28a745; color: #28a745; padding: 15px; border-radius: var(--radius-md); margin-bottom: 20px;">
<?php echo $success; ?>
</div>
<?php endif; ?>
<form method="POST" action="register.php">
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Full Name *</label>
<input type="text" name="name" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Email Address *</label>
<input type="email" name="email" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Password *</label>
<input type="password" name="password" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<div class="mb-4">
<label style="display: block; margin-bottom: 8px;">Confirm Password *</label>
<input type="password" name="confirm_password" required style="width: 100%; padding: 12px; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); border-radius: var(--radius-md); color: white;">
</div>
<button type="submit" class="btn btn-primary w-100 mb-4">Register</button>
<p class="text-center" style="color: var(--text-muted);">
Already have an account? <a href="login.php" style="color: var(--accent-gold); text-decoration: none;">Login here</a>
</p>
</form>
</div>
</div>
</main>
<?php include 'includes/footer.php'; ?>