Why can't I get hard when I'm about to have sex? Is something physically or mentally wrong with me?

Could be either. Excitation can have physical causes. It is a worthwhile visit to your doctor or a specialist like a urologist to determine if 'the equipment is in working order'. Emotional and cognitive issues can also effect excitation as well as culmination phases. If medical issues are ruled out, then seeing a therapist might help. There are also methods and programs out there to help train a response.