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.

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 :)
