Why do men have erections?

Because men have a brain that instructs glands in the body to release hormones this can occur at odd times once these hormones have been released you get an erection and maintain it until the hormone supply diminishes.