Integrating $\int_{-1} ^{1}\frac{1}{1+x^2}dx$ with the substitution $x^2=t$ gives an incorrect value of $0$. What went wrong?

Thanks @Swapnil and @Matti P for pointing that out.

Actually I can use $x^2=t $ but I'll have to split the integration. When $x=-1,t=1$ and when x<0 $dx=\dfrac{dt}{-2\sqrt{t}}$ and when $x=1,t=1$ and when x>0 $dx=\dfrac{dt}{2\sqrt{t}}$.

$$\int_{-1} ^{1}\dfrac{1}{1+x^2}dx \implies \int_{1} ^{0}\dfrac{1}{-2\sqrt t (1+t)}dt + \int_{0} ^{1}\dfrac{1}{2\sqrt t (1+t)}dt$$

$$\implies 2\int_{0} ^{1}\dfrac{1}{2\sqrt t (1+t)}dt $$

This after certain substitution it will turn out to be $\dfrac{\pi}{2}$ as well


$x^2=t$ does not mean $dx=\dfrac{dt}{2\sqrt{t}}$.

$x^2=t \implies x=\pm\sqrt{t}$

So $dx = \pm \dfrac{dt}{2\sqrt{t}}$ and to the best of my knowledge, you cannot use this for integration.

EDIT: OK, as suggested by the OP (Loop Back) in his answer, yes we can determine whether $x^2=t \implies x=\sqrt{t}$ or $x=-\sqrt{t}$ by splitting the integral and using appropriate value.