For two weeks every time I need to have a bowel movement or pass gas I have severe stomach pain. Once I go to the bathroom or pass gas it's gone. Why?

Pain before pooh. There are many reasons and causes of pain prior to defecation in your age/gender group, most of which are benign. If you have had 2 weeks of symptoms and this is an significant deviation from usual bowel habits, I would recommend that you see your primary care physician for referral to a GI doc. If you are currently pregnant, there are minimally invasive tests (sigmoidoscopy) to assess your sxs.