I've looked up the solution to this problem in the Spivak Caluclus Answers Book and found the following proof:
If $\sqrt n = a/b$, then $nb^2 = a^2$, so the factorization into primes of $nb^2$ and of $a^2$ must be the same. Now every prime appears an even number of times in the factorization of $a^2$, and of $b^2$, so the same must be true of the factorization of $n$. This implies that $n$ is a square.
I agree with all the steps up to the last one. Why is it that if some number $n$ can be factorized in a such a way that the composition would include even number of the same prime, then $n$ must be a square of some other number?
What if I take say 18. It can be represented as 3*3*2, it has an even number of primes in it and at the same time is not a square of some other number $m$.
When it is said that every prime appears an even number of times in the factorization of $n$, this is counting each prime with multiplicity.
In your example $18 = 3 \cdot 3 \cdot 2$, $3$ is listed twice. So at the end, the number of primes counted with multiplicity in the factorization of $18$ is odd.