Only the second equation is correct. The first is wrong. You had . The first equation you wrote:

.

So, I don't understand why the book gives you both equations. Only the second equation is correct. Anyway, to show you how the factoring works:

Now, factor into . Then you have .

The process the book used is called completing the square.