I'm trying to solve Exercise II.2.18b in Hartshorne, and I've constructed what appears to be a counterexample to its statement. Can someone tell me where I've gone wrong?
The statement is as follows. Let $\phi : A \rightarrow B$ be a ring homomorphism, let $X = \text{Spec } A$ and $Y = \text{Spec } B$, and let $f : Y \rightarrow X$ be the induced map. Then $\phi$ is injective if and only if the map of sheaves $f^{\#} : \mathcal{O}_X \rightarrow f_{\ast} \mathcal{O}_Y$ is injective.
My counterexample is as follows. Let $A = k[x]$ and $B = k[x,y]/(xy)$, and let $\phi : A \hookrightarrow B$ be the obvious injection. Then I claim that the associated map of sheaves is not injective. Indeed, let $p = (x) \in \text{Spec } B$ (this is a prime ideal since $B/(x) \cong k[y]$ is a domain) and $q = (x) \in \text{Spec } A$. Then $f(p) = q$. But the induced map of stalks $A_q \rightarrow B_p$ is not injective; indeed, $\frac{x}{1} \in A_q$ is nonzero but $\frac{x}{1} \in B_p$ is zero since in $B_p$ we have $\frac{x}{1} = \frac{xy}{y} = 0$.