You need to understand depth of field, as mentioned above. It's the zone of acceptable sharpness within a picture, and extends in front and behind the point of actual focus. It varies with the aperture used, and also with the magnification of the image. That is, lower f/numbers give shallow depth of field, and if you make the subject bigger, either by moving close or by fitting a longer lens, that makes it shallower too. And the reverse of course.
So, if you're close to the subject and using a longish lens with a lower f/number, as you were doing, depth of field will be quite shallow. This is often a nice effect for portraits, as it throws the background out of focus and makes the subject stand out.
The best way to make that work is to ensure both people are the same distance from the camera. The eyes are most important, so line them up in the same plane as best you can. If that's not possible or doesn't work for the picture you want, then you must increase the depth of field by using a higher f/number, so that everything you want sharp is covered. If you do that though, you will need to drop the shutter speed quite a lot to maintain correct exposure and you'll quickly run into camera shake problems unless the light is very bright.
In situation like this, the exact position of the plane of sharpest focus, ie the focus point, is very important. If you let the camera use auto-point select, it will usually go for the closest part of the subject which probably won't be accurate enough (though it's better than going got the background). So switch to single-point AF, position that over the eyes and lock it there with half-pressure on the shutter release, then recompose the picture as you want it. You need to make sure neither you nor the subject moves while you do this, but if you take more than a couple of pictures they probably will, so keep checking and resetting it. It's easy and fast once you get the hang of it.
To find out exactly how much depth of field you've got, go to
http://www.dofmaster.com/dofjs.html and input your settings - camera type, focal length, lens aperture and subject distance. It calculates it instantly. While you're there, input some different f/numbers and see how it changes.