Most miscarriages are flukes and not your fault. In fact, the majority are due to a chromosomal error in the fetus, so your body may be acting in your own best interests by ending the pregnancy early.
Chromosomes are tiny structures in each cell that carry our genes; we each have 23 pairs of them, one set from our mother and one set from our father. In a normal pregnancy, when a sperm fertilizes an egg, the chromosomes of the two cells fuse. But, sometimes the chromosomes get scrambled, which means the blueprints for fetal development are faulty, and the fetus dies within the first few weeks of pregnancy. Approximately 60 to 80 percent of miscarriages are thought to be due to this type of error. If you miscarry a second time, consider preserving the tissue you pass, if possible in a sterile saline contact-lens solution, and take it to your doctor to be sent to a lab for chromosomal testing.
For more fertility tips, check out Conceive's book, Fertility Facts: Hundreds of Tips for Getting Pregnant.