Pain while intercourse

So yesterday I was having sex with my husband and I’m 5 weeks pregnant and the whole time I was in pain on my lower stomach and after a while I started cramping really bad so we stopped. Then today we started getting into it again but no sex and I immediately started cramping. What’s going on ? Is it dangerous to have sex while pregnant ? Has this happened to anyone else ?