Some of the most basic ingredients can clean your carpet from those unsightly stains.
If you use water, equal parts white vinegar, borax warm soapy water, and salt you have just made your own homemade carpet cleaner.
After you apply the mixture to the stain let it sit for a few hours then vacuum.
If you have a stain that smells use baking soda on it and vacuum after a few hours so the baking soda has a chance to do its work.
Obviously as you see stain use a carpet cleaner on it so the stain doesn't embed itself into the carpet fibers which will make it more difficult to be removed.
Also vacuum your carpet in general often, maybe even once a week if necessary.
I have two cats and their liter box is in a closet in the hallway and sometime when they walk out it tracks the liter out so I have to make sure I vacuum that area often.
The chances are you will get a stain on the carpet eventually whether it be a dropped piece of food or drink so you should have some homemade carpet cleaner handy and ready for use.
What if you drop a plate of spaghetti on the carpet your in for some serious work if you have nothing to clean it with.
Homemade carpet cleaners should be in your home cause its better safe then sorry.