Yes, you can have sex.
I have been experiencing this same problem off and on for the past 3 months or so. You probably got the bladder infection from having sex. I have been to the gyno and she told me before you have sex, empty your bladder and then drink one glass of water. After you have sex, empty your bladder again and drink one more glass of water. That way you are able to flush out any bacteria that may get up in there during sex.
Also, if you have not gotten treated for it by a doctor, you need to go do that. Bladder infections to not feel good. If you don't take meds for it, it will keep re-occurring, I promise.
Also, if you have been to see a doc and do have medicine, make sure you take it ALL- even after you think it is completely gone. I made the mistake of not taking the rest of my medicine/antibiotics when my bladder infection went away. Since I didn't take all of it, it came back as easily as I got rid of it.
Good luck!