prepare('SELECT id FROM users WHERE username = :username OR email = :email'); $stmt->execute([':username' => $username, ':email' => $email]); if ($stmt->fetch()) { $errors[] = 'Username or email already exists'; } else { $hashed_password = password_hash($password, PASSWORD_DEFAULT); $stmt = $pdo->prepare('INSERT INTO users (username, email, password) VALUES (:username, :email, :password)'); $stmt->execute([':username' => $username, ':email' => $email, ':password' => $hashed_password]); $_SESSION['user_id'] = $pdo->lastInsertId(); header('Location: index.php'); exit; } } catch (PDOException $e) { $errors[] = 'Database error: ' . $e->getMessage(); } } } ?>
Register