I was solving this exercise from Hungerford but apparently I couldn't understand it properly since I have a counter example(?). The proposition is this:
Now, when I choose $K = \mathbf{Q}$ and $K(x_1,...,x_n) = \mathbf{Q}$($\sqrt{2}$), then $p(x)=x$ and $q(x)=1$ are both in $\mathbf{Q}[x]$, so $p(\sqrt{2})q^{-1}(\sqrt{2}) = \sqrt{2} ∈ \mathbf{Q}$($\sqrt{2})$. Clearly, $\sqrt{2} ∉ \mathbf{Q}$. So, according to the exercise $\sqrt{2}$ is transcendental over $\mathbf{Q}$. However that is not true since it is root of $f(x) = x^2-2$ which is in $\mathbf{Q}[x]$.
What am I missing here? I'd appreciate if you can help me.

What you are missing is that the $x$ in $\mathbb{Q}(x)$ is just a symbol, not a variable you can replace by a real number of your choice. That field is the set of formal quotients of polynomials with rational coefficients.
The polynomial $x^2 -2$ has no roots in the field $\mathbb{Q}(x)$ so the fact that those roots are algebraic and not transcendental (in some other extension of the rationals) does not provide a counterexample.