Erection problems (impotence) are very common, particularly in men over 40. It's usually nothing to worry about, but you should see a GP if it keeps happening.
Most men occasionally fail to get or keep an erection.
This is usually caused by stress, tiredness, anxiety or drinking too much alcohol, and it's nothing to worry about.
If it happens more often, it may be caused by physical or emotional problems.
What happens at your appointment
The doctor or nurse will ask about your lifestyle and relationships, and any problems you might be having.
They'll carry out basic health checks, such as taking your blood pressure.
They'll also examine your genitals to rule out any obvious physical cause.
If you have symptoms like needing to pee more often, your doctor may also need to examine your prostate.
They might have to examine your bottom (rectal examination).
Treatments for erectile dysfunction are much better than they used to be, and the problem often goes away.
There are specific treatments for some of the causes of erectile dysfunction.
Medicine such as sildenafil (sold as Viagra) is also often used by doctors to treat erectile dysfunction. It's also available from chemists.
Because of changes in regulations, you no longer need a prescription to get sildenafil.
But you'll have to have a consultation with the pharmacist to make sure it's safe for you to take it.
There are other similar medicines called tadalafil (Cialis), vardenafil (Levitra) and avanafil (Spedra) that work in a similar way.
You'll still need a prescription to get these medicines.
Healthy lifestyle changes can sometimes help erectile dysfunction.
Do vacuum pumps work?
Vacuum pumps encourage blood to flow to the penis, causing an erection.
They work for most men and can be used if medicine is not suitable.
They're not always available on the NHS. Speak to a doctor about where to get one.
Emotional (psychological) problems
It's more likely to be an emotional problem if you only have erection problems some of the time. For example, you still get erections in the mornings, but not during sexual activity.
Anxiety and depression can be treated with counselling and cognitive behavioural therapy (CBT).
A GP might recommend sex therapy, either on its own or in combination with other psychotherapy.
There's usually a long wait for these services on the NHS.
You can also pay to see someone privately.
Advice and support is also available from the Sexual Advice Association.