Why do I get a headache whenever I wear glasses?

Many possibilities. First you need to insure that the prescription is indeed correct. Sometimes if you have a lot of astigmatism, only partial correction is accepted, with more correction being put into the prescription in incremental steps. High amounts of myopia or hyperopia and astigmatism will cause a distorted perception of your environment. It may take a while to get adjusted to these types of prescriptions.
Wrong Rx? There is no way to answer this without measuring the glasses and your prescription. The prescription could be wrong, you may not be used to it, the lens may be off center. There are many options. See your eye doctor.