Pain while passing stools could be due to anal fissure
, or piles. You have not mentioned if you have hard stools, bleeding during or after stools. A visit to your family physician/surgeon would be helpful inorder to diagnose the condition.
In the meanwhile follow-
1) Dietary modification--- Include diet rich in fiber like green leafy vegetables, fruits (avoid pomegranate-as its known to cause hard stools), (banana, papaya, apples are helpful), kishmish ,oats and cucumber ,which would help in softening the bulk of stools
2) Drink plenty (at least 12-13 glasses) of water
3) Apply Xylocaine
2% jelly around the anal region, before and after passing stools. This would help in relieving the pain to some extent.
4) Sitz bath- take a tub filled with hot water(the heat should be tolerable) and sit in it till the water becomes warm. Repeat it at least 2-3 times/day .
Do not self medicate .
has safe and effective medicines for both the conditions.