1. Drinking too much. Alcohol affects the circulatory system (which is why your cheeks get flushed when you drink), and there is a point for every person where the brain will prioritize the continued operation of the lungs and heart over a dick getting hard. This point is different for everyone, and it can vary based on things like how tired a person is, how stressed out they are, or what they're drinking. Drinking at, say, a tailgate is a recipe for boner-disaster. Even if you don't feel drunk because you've been slowly drinking all day, the amount of alcohol in your blood is high and the effect is the same: no hard dick. Similarly, playing beer pong for hours or drinking a 12 pack of beers is a good way to overwhelm your blood flow and stay frustratingly soft all night. Le sigh.
2. Prescription drugs. The two main categories of drugs that affect young males' erections are antidepressants (which can inhibit erection altogether, delay orgasm, or both) and stimulants like Adderall which, like cocaine, doesn't usually keep a boner from happening but will inhibit orgasm effectively. And no, the girl you're having sex with isn't psyched that you can go for an hour at a stretch. Also, if you're not prescribed a drug like Adderall and you're taking it anyway, the side effects may be worse.
3. Stress. I see people all the time who are experiencing some incredibly stressful event--writing a dissertation, just found out they have herpes, parent illness or death--who have erectile dysfunction. The brain can only focus on so many things at a time, and overwhelming stress is a sure-fire boner-killer.
4. Condoms. Penises come in all shapes and sizes, but condoms are almost all the same: a cylindrical tube that is the same circumference at the top and bottom. Some, like the Magnum, are more baseball-bat shaped for those guys who are wider at the top, but no condom out there is designed for the guys who are really wide at the base. The ring at the bottom of the male condom should be snug, but not uncomfortably tight, and definitely not painful. This isn't an excuse to not use condoms, but if a guy suspects that condoms are the problem because he has can stay hard when he's masturbating or during oral sex, trying a few different condoms is key.
5. Feelings. I get all mooshy inside when guys come in and they're all emotional about their new partner and can't stay hard because they're so nervous about where the relationship is going. I've seen this happen with guys from all over the map--gay, straight, religious, fratty--and it's always devastating (but also kind of endearing!). The last thing you want when you have a new partner is for the sex to not work the way you envisioned. This problem has a pretty easy solution: redirect and wait. Don't lie and say it's never happened (if it has), just be honest and say that you really like the person, you're nervous about wanting to impress them, and then impress them with your other skills. If you don't have any other skills, develop them now.
6. Unhealthy lifestyle. This can include all of the above factors or it can stand on its own. Remember that the dick is part of the circulatory system, and remember from 4th grade health class that the cardiovascular system is made stronger through exercise and weaker by its absence. Guys who are totally sedentary, overweight, eat junk food, sit in front of a computer for 16 hours a day (sound like any PhD students you know?) are setting themselves up for erectile failure. An erection is not a crucial body function and if you're not taking care of your heart, you are not guaranteed hard-ons when you want them. Go to the gym.
7. The Heterosexual Closet. Guys I see are frequently stuck in a "good girl/bad girl" rut--they can get hard and have great sex with "bad girls" but when they get the "good girl" that is socially acceptable girlfriend material, they don't respond the same way. Sometimes it's not the partner but a particular type of sex a guy wants to have but is afraid to ask for with a longer term partner with whom he's emotionally vulnerable. It can be scary to ask for something you want sexually, especially if you discovered you liked it under casual circumstances; asking a one night stand to choke you is easy, because you might not see them again. But telling your girlfriend that you like to be hit during sex could make things awkward. The only way to get the sex you want is to ask for it. If you're not getting what you want from "good girls" then, guess what? You're trapped in the heterosexual closet and it's time to come out.
So if you're panicked about your boners or just want to try Viagra because you think it'll be awesome, save your money. You don't need it, it won't do anything, and how emasculating to depend on a medication to get a hard-on anyway.
Happy Boner Summer, everyone.