ANSWER:

If you remembered soon after salam, stand up and offer the missed rakah and offer 2 prostrations after salam for forgetfulness. 

But if you remembered this long after the pray was over, your prayer is invalid and you must offer it again. 

What should a person do if he joins the prayer when the imaam has alredy finished one rakat and at the end the person forgets that he had missed one rakat and finishes the salah with the imaam, does he have to repeat the whole salah or not?

Prayer |