If $f(g(x))=x$ is $f$ an injective function? 
Let $ f:\mathbb R\to \mathbb R $ . If $f(g(x))=x$ then is $f$  an injective function?

Well, I proved it to be true. But honestly I have a strong feeling that my proof is wrong.
Here's my proof:
Assume $f(a_1)=f(a_2) = x$ and we want to prove that $a_1 = a_2$ .
if $f(a_1)=f(a_2) = x,$  then $a_1 = g(x)$  and   $a_2 = g(x) $. meaning $a_1 = a_2$.
Therefor f is injective. 
Is my proof wrong? I assume that not only that my proof is wrong but also that this isn't true at all. But I'm having a hard time to find a contradicting example.
 A: Recall the definition of $\arctan$:

$\arctan$ is the only continuous function $\Bbb R\to \left(-\frac\pi2,\frac\pi2\right)$ such that $\tan\arctan x=x$ for all $x\in\Bbb R$.

Now, it is clear that $\tan$ can be extended to a function $\Bbb R\to\Bbb R$ by assigning arbitrary values to $x=k\pi+\frac\pi2$. Would such an extension be injective?
A: It is injective on the range of $g$, but not necessarily otherwise.
To see that it is injective on this set, suppose $a\neq b$ are two elements in the range of $g$. There exist $x\neq y$ such that $a=g(x)$ and $b=g(y)$. Then $f(a)=f(g(x))=x$ and $f(b)=f(g(y))=y\neq f(a).$
The problem is that $g$ might not be surjective. If it isn't then the relationship you have tells you nothing at all about the behaviour of $f$ on values that you can't get by applying $g$, so in this case there is no reason for injectivity. As I was writing, G. Sassatelli has given an example of this :)
A: Your proof is flawed as comments point out, but more fundamentally it's flawed because the statement is false.
$f$ need only be injective over the range of $g$.
For example, consider $g(x) = e^x$ and define $f$ as
\begin{equation}
    f(x) =
    \begin{cases}
      \ln(x)& \mathrm{if}\, x > 0 \\
      0        & \mathrm{otherwise}
    \end{cases}
\end{equation}
A: If $f(g(x))=x$ for all $x$ then $f$ is onto. I don't know if you are using the usual notation for function composition, if you are, then the result is not true. 
If $g(f(x))=x$ for all $x$ then $f$is one-one. 
A: In fact, it is not true.
Example: Define $f(x_1,x_2,x_3, \cdots)=(x_2,x_3,x_4,\cdots)$ and $g(x_1,x_2,x_3,\cdots)=(0,x_1,x_2,x_3,\cdots).$
Then $f(g(x_1,x_2,x_3, \cdots))=f(0,x_1,x_2,x_3,\cdots)=(x_1,x_2,x_3, \cdots).$ But $f$ is not injective.

It is, however, true that $g$ is injective.

Let $g(x)=g(y).$ Then $f(g(x))=f(g(y)).$ This implies $x=y.$ Therefore, $g$ is injective.
