If $f:X\rightarrow Y$ is a continuous function and $Y$ is connected, then $X$ is also connected. If $f:X\rightarrow  Y$ is a continuous function and $Y$ is connected, then $X$ is also connected.
I know that for this to be true, P has to be a homeomorphism so I'm trying to find a counterexample and I do not know if I found it serves me:
Take $f:[1,2)\cup (2,3]\rightarrow [1,3]$ where $f(x)=x$ and we are taking $X$ and $Y$ with the subspace topology of $\mathbb{R}$ dated with the standard topology.
 Is this counterexample okay? Is there a mistake in it? Thank you very much.
 A: This is false even when $f$ is surjective. If $f:X\to Y$ is continuous and $X$ is connected, then $Y$ is connected.
But if $f:X\to Y$ is continuous and $Y$ is connected, that does not mean $X$ is connected.
For example, suppose
\begin{align}
X & = \{(\cos\theta,\sin\theta) : \theta\in\mathbb R\bmod (2\pi)\} \cup \{(3+\cos\theta,\sin\theta) : \theta\in\mathbb R\bmod(2\pi)\}, \\[10pt]
& \qquad \text{so that $X$ is the union of two disjoint circles in the plane, and} \\[10pt]
\text{for } & x\in X,\text{ we have } f(x) = (\cos\theta,\sin\theta).
\end{align}
Then $f$ is continuous and its image is connected, but its domain is not connected.
A: Your counterexample is valid because $[1,2)\cup(2,3]$ is disconnected, $[1,3]$ is connected, and $f$ is continuous. Which of these facts are you not sure about?
Another example that is a bit simpler (and shows that it's still false when $f$ is surjective) is to take the constant function $f:\{0,1\}\to\{0\}$, where $\{0,1\}$ and $\{0\}$ have the discrete topology.
A: Note that any function $f: X \to Y$ is continuous if $X$ has the dicrete topology. 
The discrete topology on $X$ is (totally) disconnected if $X$ has at least $2$ points.
So any (connected or not) non-trivial space is the continuous image of a disconnected space, so it fails very drastically.
A theorem where you can go back:

Let $f: X \to Y$ be a (surjective) quotient map where all sets $f^{-1}[\{y\}], y \in Y$ are connected. Then $Y$ connected implies that $X$ is connected.

A: Let $D = [-2,-1]\cup[1,2]$, $R = [1,4]$ and $f = x\mapsto x^2$.  The function $f$ is surjective.  Question resolved.  The direct image of a connected set under a continuous function is continuous.  All bets are off with the inverse image.
