38395-vm/register.php
Flatlogic Bot 60a638c740 sadiq
2026-02-13 08:56:51 +00:00

80 lines
3.3 KiB
PHP

<?php
$page_title = "Join AFG CARS";
include 'includes/header.php';
$error = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$full_name = trim($_POST['full_name'] ?? '');
$email = trim($_POST['email'] ?? '');
$password = trim($_POST['password'] ?? '');
$phone = trim($_POST['phone'] ?? '');
if ($full_name && $email && $password) {
$pdo = db();
// Check if email exists
$stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$error = "Email already registered.";
} else {
$pass_hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (full_name, email, password, phone) VALUES (?, ?, ?, ?)");
if ($stmt->execute([$full_name, $email, $pass_hash, $phone])) {
$_SESSION['user_id'] = $pdo->lastInsertId();
$_SESSION['full_name'] = $full_name;
$_SESSION['role'] = 'user';
header('Location: user/dashboard.php');
exit;
} else {
$error = "Registration failed. Please try again.";
}
}
} else {
$error = "Please fill in all required fields.";
}
}
?>
<div class="container py-5">
<div class="row justify-content-center">
<div class="col-md-5">
<div class="card border-0 shadow-sm p-4" style="border-radius: 20px;">
<div class="text-center mb-4">
<h2 class="fw-bold">Create Account</h2>
<p class="text-muted">Join the premier Afghan car marketplace</p>
</div>
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>
<form method="POST">
<div class="mb-3">
<label class="form-label">Full Name</label>
<input type="text" name="full_name" class="form-control" placeholder="John Doe" required>
</div>
<div class="mb-3">
<label class="form-label">Email Address</label>
<input type="email" name="email" class="form-control" placeholder="name@example.com" required>
</div>
<div class="mb-3">
<label class="form-label">Phone Number</label>
<input type="text" name="phone" class="form-control" placeholder="+93 700 000 000">
</div>
<div class="mb-4">
<label class="form-label">Password</label>
<input type="password" name="password" class="form-control" placeholder="••••••••" required>
</div>
<button type="submit" class="btn btn-primary w-100 py-2 mb-3">Create Account</button>
</form>
<div class="text-center">
<p class="text-muted small">Already have an account? <a href="login.php" class="text-primary fw-bold text-decoration-none">Sign in</a></p>
</div>
</div>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>