prepare("INSERT INTO users (username, password) VALUES (?, ?)"); if ($stmt->execute([$username, $password])) { $_SESSION['user_id'] = $pdo->lastInsertId(); header('Location: index.php'); } else { echo "Username taken."; } } elseif (isset($_POST['login'])) { // Login $stmt = $pdo->prepare("SELECT * FROM users WHERE username = ?"); $stmt->execute([$username]); $user = $stmt->fetch(); if ($user && password_verify($_POST['password'], $user['password'])) { $_SESSION['user_id'] = $user['id']; header('Location: index.php'); } else { echo "Invalid credentials."; } } } ?> Register/Login

Register

Login