Wrong answer for this integral: $\int \frac{x^2+1}{x^4-x^2+1}dx$ 
$$\int \frac{x^2+1}{x^4-x^2+1}dx$$

Dividing both sections by $x^2$ and adding $1$ to the denominator I get: $$\int \frac{1+\frac{1}{x^2}}{(x-\frac{1}{x})^2+1}dx$$
Setting $x-\frac{1}{x}$ as $t$ I get: $$dt=1+\frac{1}{x^2}dx$$
Then I have written it in the following form: $$x-\frac{1}{x}+\int \frac{dt}{t^2}.$$
Then I wrote it like this: $x-\frac{1}{x}-\frac{1}{t}$ , substituting the $x'$ back: $$x-\frac{1}{x}-\frac{1}{x-\frac{1}{x}}.$$
I know the integral I get is wrong because as I substitute some $x$'s in the most upper integral I get different results from those I get when substituting the same values in the final answers. Where is my mistake?

The substitution $t=x-\frac{1}{x}$ is indeed a good starting point, but I'm not sure I understand your reasoning after that. The substitution rewrites your indefinite integral as $\int\frac{dt}{t^2+1}$ (as others have noted), which you seem to have rewritten as $t+\int\frac{dt}{t^2}$. That suggests to you me you confused your integral for $\int(1+\frac{1}{t^2})dt$, i.e. you confused $\frac{1}{1+t^2}$ with $1+\frac{1}{t^2}$.
