To get rid of mildew, you must first get rid of the source. To thoroughly dry your carpet, use a dehumidifier, and a wet-dry vac. This is just the first step, of course, and drying the carpet may take several days. Remember that the carpet is just the top layer. The padding layer underneath can hold a lot of moisture and even the flooring underneath can hold moisture in. Turning the heat up and keeping both a fan and dehumidifier running for a few days should get your carpet dry.
To clean mildew out of carpet and eliminate the odor, you must use a deep carpet cleaner. This may seem redundant as most carpet cleaners use a cleaner and water mixture, but once the carpet has dried the mildew should have stopped growing and spreading -- which leaves you with having to remove the mildew remains and odor. Products by Rug Doctor and others for use with steam cleaners will eliminate any sign of mildew and even help prevent mold. A deep cleaner will infuse the fibers and padding with cleanser and then suck it all back out, along with the mildew and smell. Keep your dehumidifier running and the fans on to make sure that the carpet is once again good and dry. Avoid walking on the carpet.
Remaining Odors and Future Prevention
It can be really hard to get that musty mildew smell out of the room with the carpet. Keeping the area dry is the first step to eliminating the odor. The next step is to combat and absorb any remaining odor. Sprinkle the carpet with baking soda and place a few small bowls of vinegar around the room. Allow these to sit overnight. In the morning, remove the vinegar and vacuum the carpet. You may have to repeat this step a few times, but before long your carpet and room will smell fresh and clean.