Back in 2009, I wrote a blog post giving some basic information on how to fix ungrounded three-prong outlets. The information in that post is still mostly applicable today, but there are few nitty-gritty details missing from that post, and there have been a few code changes since I wrote that, making the repair for an ungrounded three-prong outlet a little bit more complicated.
To start off, the third prong on a plug is for the ground wire, and its job is to bond electrical components. Under normal conditions, there should never be any current on the ground wire. Think of it as an emergency lane on the highway; things should work just fine without it, but when something goes wrong, you better have it. If a three-prong outlet is installed with only two wires and no grounding path, we call it an ungrounded three-prong outlet. This is a common defect at old houses, and sometimes at newer homes where some hack has been messing with the wiring. An ungrounded three-prong outlet increases the potential for shocks or electrocution, and prevents surge protectors from doing their job, which may allow for damage to electronic components.
Any cheap electrical tester will identify an ungrounded three-prong outlet, unless someone really went out of their way to fool the three-prong tester, which would be highly unethical and dangerous. I'm not going to explain how that's done.
So anyway, back to repairing an ungrounded three-prong outlet. The electrical code gives several options for this repair, which are listed under section 406.4(D) of the 2014 National Electric Code (NEC).
If a ground path exists, you need to use it. NEC Section 406.4(D)(1) says that if a grounding path exists, it needs to be used. Ground paths have been required throughout homes since 1962. This means that the only acceptable repair for an ungrounded outlet in a home built after 1962 is to ground the outlet. If no ground path exists on a home this age, someone really screwed up. In my old post on fixing ungrounded outlets, I show how to use a two-lead tester to see if the electrical box is grounded.
If the metal box is properly grounded, the most common way of grounding the outlet to the box is to simply connect a wire to the box, as shown below. This is called an equipment bonding jumper.

There are other methods listed under section 250.146 of the NEC, but I'm not going to try explaining those.
If no ground path exists, there are three options for replacing the outlet, given under NEC section 406.4(D)(2)(a), 406.4(D)(2)(b), and 406.4(D)(2)(c).