First of all, *all* guys have this happen occasionally. However, erections are really, really sensitive to anxiety, and a lot of guys are anxious
about their erections. So, maybe he lost his erection once and panicked, thinking it would happen again, which of course virtually guarantees it will. The porn/masturbation might be a result of that anxiety; he could be essentially reassuring himself that he still can get aroused, have an erection, etc.