hi..thanks for writing.. i have understood your concerns,..
erectile dysfunction at this stage is mostly due to psychological issues. theses can be anxiety about the failure in the bed as previously, anxiety about partner's satisfaction, conflict with partner, sex in a hurry, sex with hooker, sex at places where chance of being caught is high, anxiety due to life stress, depression etc.. lots of psychological issues are there..
in your case i feel the anxiety about the repetition of similar failure is the cause..
for maintaining proper erection throughout sex, adequate stimulation shud be there from both side. you shud spend more time in foreplay and it shud also continue during penetrative sex. foreplay has same importance as penetrative sex for gaining better pleasure.
you can also control your anxiety by meditation, yoga,
relaxation therapy etc.
in my opinion , you shud
consult a psychiatrist or
sexologist and undergo sexual therapy and
counselling. sex is more than just penetration you shud learn more about sex by watching porn videos also.
you shud not take any drugs without consultation to doctor.
i hope this will be helpful to you, best of luck..