How do you pray for someone who is ill? Also, how do you pray for someone who has to go through surgery?
You can say anything you want. There is no need for special words. Below is a prayer from the Prophet :
Narrated `Abdul `Aziz:
Thabit and I went to Anas bin Malik. Thabit said, "O Abu Hamza! I am sick." On that Anas said, "Shall I treat you with the Ruqya of Allah's Messenger (ﷺ)?" Thabit said, "Yes," Anas recited, "O Allah! The Lord of the people, the Remover of trouble! (Please) cure (Heal) (this patient), for You are the Healer. None brings about healing but You; a healing that will leave behind no ailment."
Sahih al-Bukhari 5742
Below is the Arabic transliteration of the prayer:
allāhumma rabba al-nās mudhhiba al-bās ishfi anta al-shāfī la shāfiya illā anta, shifāʾan la yughādiru saqman