prepare("UPDATE users SET firstName = ?, lastName = ? WHERE id = ?"); $stmt->bind_param("ssi", $firstName, $lastName, $userId); if (!$stmt->execute()) { $_SESSION['error'] = "Failed to update name. Please try again."; header("Location: profile.php"); exit; } $stmt->close(); // Optionally update session data if you store these fields there $_SESSION['user']['firstName'] = $firstName; $_SESSION['user']['lastName'] = $lastName; $_SESSION['success'] = "Name updated successfully."; header("Location: profile.php"); exit;