When a person receives an Aliya to the Torah, he recites the Beracha "Asher Bahar Banu Mi’kol Ha’amim" before the reading, and then the Beracha "Asher Natan Lanu Torato Torat Emet" after the reading.
If the Oleh (person receiving the Aliya) mistakenly began reciting "Asher Natan Lanu" before the reading, and the congregation immediately corrects him, he may simply recite right then and there "Asher Bahar Banu." This will then be a perfectly valid Beracha, and his recitation of the introductory phrase "Baruch Ata Hashem Elokenu Melech Ha’olam" counts for the correct Beracha. If he did not catch his mistake until he completed the Beracha, then he does not have to then recite the correct Beracha. The reading proceeds as usual, and then after the reading he recites the Beracha "Asher Bahar Banu," which should have been recited before the reading. This is the ruling of the Mishna Berura (Rav Yisrael Meir Kagan of Radin, 1839-1933). Likewise, if one mistakenly began reciting the wrong Beracha after the reading, and he catches himself before completing the Beracha, he simply corrects himself. Hacham David Yosef writes that even if the Oleh realized his mistake toward the end of the Beracha, after the second instance "Baruch Ata Hashem," he may correct himself by reciting, "Asher Natan Lanu Torato Torat Emet…" Even though he had almost completed the incorrect Beracha, it is nevertheless not too late to correct his mistake. If he completed the entire Beracha before realizing his mistake, he does not have to then recite the correct Beracha. Although there are different opinions among the Halachic authorities in this regard, we follow the rule of "Safek Berachot Le’hakel," and the Beracha is not recited due to the Halachic uncertainty involved.
Before reciting the first Beracha over the reading, the Oleh should first declare, "Hashem Imachem," to which the congregation responds by saying, "Yebarechecha Hashem." This custom is mentioned by the Hesed La’alafim (Rav Eliezer Papo, 1786-1827), and is likely intended for the purpose of calling the congregation to attention for "Barechu." The Hesed La’alafim writes that it is preferable to say "Hashem" and not G-d’s actual Name when declaring, "Hashem Imachem."
The Shulhan Aruch (Orah Haim 140) addresses the case of an Oleh who faints in the middle of the Aliya, or needs to be replaced for some other reason. The majority of the Rishonim maintained that the person who replaces the Oleh recites the first Beracha again and then repeats the reading from the beginning of the Aliya. Since the entire text requires a Beracha both before and after, the second person must recite a new Beracha before he begins reading. The Shulhan Aruch then cites a different view, that of the Rambam (Rav Moshe Maimonides, Spain-Egypt, 1135-1204), who understood the Talmud Yerushalmi as saying that the second person does not recite the first Beracha, and recites only the Beracha after the reading. After citing both views, the Shulhan Aruch rules in accordance with the first position. However, given the different opinions that exist, we apply the rule of "Safek Berachot Le’hakel," and so the second Oleh does not recite the first Beracha. Nevertheless, the Hid"a (Rav Haim Yosef David Azulai, 1724-1807) writes that if the person insists on following the Shulhan Aruch’s ruling, he may be allowed to recite the first Beracha, as well. The Hid"a explains that according to some authorities, one should recite a Beracha required by the Shulhan Aruch’s ruling even if others disagree, and although we do not generally follow this view, one who wishes to recite a Beracha required by the Shulhan Aruch may be allowed to do so.
Summary: If the Oleh recites before the Aliya the Beracha that should be recited after the Aliya, or vice versa, he may correct himself and recite the proper Beracha, as long as he had not completed the incorrect Beracha. If he did not realize his mistake until after he completed the incorrect Beracha, he does not then have to recite the correct Beracha. If this happened when the Oleh recited the Beracha before the Aliya, and he recited the Beracha that should be recited after the Aliya, then after the Aliya he recites the Beracha that is normally recited before the Aliya. If the Oleh fainted during the Aliya or needed to be replaced for some other reason, the new Oleh begins the Aliya anew but does not repeat the first Oleh’s Beracha; he recites only the Beracha after the Aliya.