Let $A$ be a commutative ring with one, and $A^n, A^m$ be free modules over $A$. Let $\varphi:A^m\rightarrow A^n$. I want to show that if $\varphi$ is injective, then $m\leq n$. Similarly, if $\varphi$ is surjective, then $m\geq n$.
My attempt: Let $\varphi:A^m \rightarrow A^n$ be $A$-linear. Let $x_1,...,x_m$ and $y_1,...,y_n$ be bases of $A^n$ and $A^m$, respectively. By the universal property of free modules, $\varphi$ is induced by a function $\tilde{\varphi}:\{x_1,...,x_m\}\rightarrow \{y_1,...,y_m\}$. We now know that there exists an injective map between two sets $X$ and $Y$ if and only if $\mid X\mid \leq \mid Y \mid$. A similar argument delivers the second statement.
Is my solution correct? If not, where does it fail?