How can you tell if it's an STD or UTI when you experience yellow discharge, burning pee, and painful erections?

You test for it. Discharge, burning pee & painful erections are not normal. They are a definite sign of something infecting/irritating the penile outlet. While some STD's have no such symptoms this is a classical presentation. Go have yourself tested for both. If you have had a sexual exposure this is most likely gonorrhea but could be chlamydia. Proper treatment will depend on what is found.