All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
If you entered the prayer with the intention of performing the Maghrib prayer and then changed your intention to that of ‘Ishaa’, then the Maghrib prayer is invalid. The reason for this is because you changed your intention and the ‘Ishaa’ prayer is invalid as well because you did not intend it from the beginning. Changing your intention from one obligatory prayer to another during one invalidates both. The Hanbali scholar, Al-Hajjaawi said: "Changing the intention from one obligatory prayer to another during it invalidates both." Consequently, you are required to make up for the ‘Ishaa’ prayer. You are also required to make up for the Maghrib prayer if you had not already performed it.