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.
The entry of something into the throat by mistake, or through forgetfulness or by force does not invalidate fasting. Allaah The Almighty Says (what means): {Our Lord, do not impose blame upon us if we have forgotten or erred.} [Quran 2:286]
Allaah The Exalted also Says (what means): {And there is no blame upon you for that in which you have erred but [only for] what your hearts intended.} [Quran 33:5]
The Messenger of Allaah, sallallaahu ‘alayhi wa sallam, said: "Allaah pardons my nation for what they do by mistake, through forgetfulness and coercion " [Ibn Maajah on the authority of Ibn ʻAbbaas ; Al-Albaani: Saheeh]
Your fasting is valid, Allaah willing, if this happened by mistake. However, if you deliberately swallowed what came out of your stomach after it reached your mouth, despite the ability to spit it out, then you should make up for this. Sulaymaan Al-Jamal, a Shaafiʻi scholar said, "If one belches when he is fasting and something comes out of his stomach, he should spit it out and wash his mouth. This does not invalidate his fast even if it is repeated several times." [End of quote]
Allaah Knows best.