An erection is when blood rushes into and fills the penis, causing it to enlarge and stiffen enough to have sex.
Erections are a reflex--meaning not within a person's control--so a cause can't always be identified. Anything from a brush of fabric to the need to urinate can cause an erection, but most often, erections occur as a response to sexual thoughts or stimulation.