Let $k$ be a field, $X_1=X_2=\mathbb{A}^1_k=\operatorname{Spec}(k[x])$, $P$ the point corresponding to the maximal ideal $(x)$, $U_1=U_2=\mathbb{A}^1_k-\left\{P\right\}$ and $\phi:U_1 \rightarrow U_2$ the identity map. What do we mean by the phrase "let $X$ be obtained by glueing $X_1,X_2$ along $U_1,U_2$ via $\phi$"? (Example 2.3.6 page 76 in Hartshorne)
3 Answers
Well it seems I spend rather too much time on answering this (the answers that have been posted in the mean time cover everything), but I don't feel like deleting this either.
"Gluing things together" is a very general idea found everywhere in mathematics, and I'm not sure if I can give it justice here.
Let's suppose we begin with topological spaces. So let $X_1, X_2$ be topological spaces, $U_i \subset X_i$ open subsets, and $\varphi: U_1 \to U_2$ a homeomorphism. When we say "$Y$ is obtained by gluing $X_1$ and $X_2$ along $\varphi$", we mean that $Y$ is the quotient of the space $X_1 \amalg X_2$ (disjoint union) by the equivalence relation which identifies $x \in U_1$ and $\varphi(x) \in U_2$, and nothing else.
That is to say we have a quotient map $q: X_1 \amalg X_2 \to Y$, and a map $f: Y \to Z$ is continuous iff $fq: X_1 \amalg X_2 \to Z$ is continuous. Moreover, $A \subset Y$ is open iff $q^{-1}(A)$ is. I'm sure we can extend these observations into a universal property determining $Y$. But you are asking what the gluing is, and this describes it for topological spaces, I'll leave it to you to sort out in more detail why this definition is sensible.
Now let's do the same for schemes. $X_i$ are now schemes, and $U_i$ are still open subsets. With their canonical subscheme structure, they become open subschemes. We are looking for a scheme $Y$ which behaves similarly to the $Y$ we had above when dealing with topological spaces. Well, let $Y$, as a topological space, be the topological quotient. Note that $X_i$ are naturally open subsets of $Y$, and they cover $Y$. On each of the $X_i$ we are given structure sheaves, and we want to fabricate a structure sheaf on $Y$. But now sheaves can also be glued! This way we obtain a structure sheaf on $Y$, and it is easy to see that the ringed space $Y$ constructed in this way is still a scheme (locally ringed space locally isomorphic to an affine scheme). This is the "scheme obtained by gluing the $X_i$, and it has all the same nice properties as the gluing procedure for topological spaces has.
To illuminate the gluing of sheaves slightly further: Let $F$ be the presheaf $U \mapsto \{(a, b) \in O_{X_1}(U \cap X_1) \oplus O_{X_2}(U \cap X_2) : a_x = \varphi^\#_x(b_x) \text{ for all } x \in U \cap U_1 = U \cap U_2\}.$ Then you can check that $F$ is in fact a sheaf, and indeed $F = O_Y$.
What does all this mean in your case? Well, if you sort through the topological gluing procedure, you will see that $Y$ is basically the affine line, just with one extra point, a "double origin". The only open subset of $Y$ which is not an open subset of one of the $X_i$ is $Y$ itself. It is an easy exercise that $O_Y(Y) = k[x]$. This describes $Y$ completely.
When we glue two schemes together, we create a new scheme with a topology nearly the same as the disjoint union, except we identify an isomorphic pair of open sets between the schemes and use them to join/glue the schemes together.
In this example, we're glueing two copies of the affine line. It may be helpful to use different letters to represent their coordinate rings, so let $X_1 = \text{Spec }(k[x])$ and $X_2 = \text{Spec }(k[y])$. They are certainly isomorphic as is (via the map $k[x] \rightarrow k[y], x \mapsto y$), but we'll focus on the open sets $U_1 = D(x)$ and $U_2 = D(y)$ which are then isomorphic as well (via the same map).
When we glue these two open sets together, we use the isomorphism to consider them as one set. So, with the exception of the origin, our glued scheme looks like a regular affine line. But each scheme $X_1$ and $X_2$ has its own distinct origin, so the glued scheme now has two origins! We get an affine line with a double point at 0, a non-separated scheme.
Generally, you can think of a projective scheme as a glueing of affine schemes. The glueing process is that of building a scheme from the ground up.
Formally, to glue schemes two schemes $X,Y$ along open subsets $U \subset X$,$V \subset Y$, you specify an isomorphism $U \to V$, and think of identified points as the same. (you need an isomorphism on the level of sheaves also, of course)
This example can be visualized nicely. Imagine two strips of paper (each representing the affine line $\text{Spec } k[x]$, and glue them together everywhere, except at one point. So this scheme looks everywhere like the affine line, but it has the point P doubled (where we didn't glue the paper slips).