- Voy a la farmacia por medicina.
- Voy a la farmacia para medicina.
Which is correct?
Wimi's answer is indeed correct. Perhaps there is some confusion on the part of OP around the use of "para". The preposition "para" could be used with an infinitive:
The preposition "para" can be followed by nouns but not in the case at issue, for example:
With "ir", meaning "go and get", the preposition "por" is required.
As explained by RAE, "going to fetch something" is usually translated as "ir a por algo" in Spain and as "ir por algo" in Latin America. So
Voy a la farmacia a por medicina
and
Voy a la farmacia por medicina
are both correct.
From "Complete Spanish Grammar, 3rd Edition" by McGraw Hill Education:
Para indicates:
Por indicates:
To answer your question:
por is correct, it can be interpreted that you are going to the pharmacy because of the need for medicine.
To use para, You would rephrase to indicate the pharmacy as your destination (Estoy saliendo para la farmacia) or the purpose of going there (Voy a la farmacia para comprar medicamentos).