Painting over wall with peeling paint
First, make sure you get all (and I do mean all) of the loose paint off the wall. If you get a fairly flexible wallpaper scraper you should be able to bring most of it up. Keep going for that extra 5 minutes after you think you've finished.

Then sand the remaining paint to feather the edges so that they are as smooth as possible.

Next get some filler (spackle I think it's called in the states) and fill in any cracks and large holes. You can also use it over any edges that still seem harsh. When it's dry a light sand will smooth out the imperfections - but don't let it get too dry as it can go very hard.

Then wash the walls down with warm (mild) soapy water, then rinse off with fresh clean water. Allow to dry then prime the wall with either a specialist primer or a watered down coat of emulsion. This will also help find any last imperfections which you can fill and reprime.

Then the wall is ready to paint.