It sounds like the chemical you used to "clean" the carpet actually set the stain more permanently. This can happen depending on the chemistry involved and for this reason I have heard that one should avoid using chemical cleaners (unless you really understand the chemistry).
The best way to get out stains from food/coffee/etc is to quickly apply water and blot the area, to lift the staining material. The goal is to soak it out using water before it sets. This also applies to clothing stains.
For stubborn stains you can spray on a mix of water and a small amount of laundry detergent from a spray bottle, and put some dry white towels over the wet stain with a heavy weight on top. Leave for a few days and let the towels wick up the water and hopefully the stain along with it.
For organic stains like coffee and red wine, I have also heard the following tip (although I have not had chance to use it yet). If you have an organic stain, and synthetic carpet fibers (ie, NOT wool or cotton), then supposedly you can mist on some hydrogen peroxide via a spray bottle nozzle, wait a few minutes, and blot dry with a white towel. Note that since I cannot personally vouch for this method you may wish to try it out in inconspicuous area first.
These tips may not work on stains that have already set or been chemically treated, but hopefully they will help someone.