prepare("SELECT COUNT(*) FROM users WHERE email = :email OR username = :username"); $stmt->execute(['email' => $email, 'username' => $username]); if ($stmt->fetchColumn() > 0) { $errors[] = 'Username or email is already taken.'; } else { // Hash password and insert new user $password_hash = password_hash($password, PASSWORD_DEFAULT); $insert_stmt = $pdo->prepare("INSERT INTO users (username, email, password_hash, role) VALUES (:username, :email, :password_hash, 'user')"); $insert_stmt->execute([ ':username' => $username, ':email' => $email, ':password_hash' => $password_hash ]); // Log the user in immediately $_SESSION['user_id'] = $pdo->lastInsertId(); $_SESSION['username'] = $username; $_SESSION['role'] = 'user'; header("Location: dashboard.php"); exit(); } } catch (PDOException $e) { error_log("Database error: " . $e->getMessage()); $errors[] = 'An internal error occurred. Please try again later.'; } } } ?> Create Account - Car Sells in Afghanistan

Create Your Account

Join us to find your dream car in Afghanistan.

Already have an account? Login here.

Back to Home