Let $p$ be an odd prime and let $(a,p)=1$. There is no guaranteed that there is a solution to $$x^2\equiv a \pmod p$$
What is wrong here:
$$a^{(p-1)/2}≡(x^2)^{(p-1)/2}\equiv x^{p-1} \pmod p$$
It is known that $(a,p)=1$, so $(x,p)=1$; then we get:
$$a^{(p-1)/2}\equiv x^{p-1}\equiv 1\pmod p$$
so I just proved that every $a$ is QR even if it is not. Well that is just wrong.
Where am I wrong here?
The existence of an $x$ with $$a^{(p-1)/2}\equiv (x^2)^{(p-1)/2}$$ modulo $p$ cannot be assumed if $x^2\equiv a$ modulo $p$ has no solution.
In fact, if $a$ is no quadratic residue modulo $p$ and $(a,p)=1$, then $$a^{(p-1)/2}\equiv -1$$ modulo $p$ holds.