The Messenger of Allah ﷺ said, "The best things a man can leave behind after his death are three. A righteous child who prays for him, an ongoing charity whose reward reaches him, and knowledge that is acted upon after him."
قال رسول الله ﷺ: خير ما يخلف الرجل من بعده ثلاث: ولد صالح يدعو له، وصدقة تجري يبلغه أجرها، وعلم يعمل به من بعده.
Ibn Majah (241) narrated it from Ismail bin Abu Karima Harrani, who said, Muhammad bin Salama told us, from Abu Abdul-Rahim, who said, Zayd bin Abu Unaysa told me, from Zayd bin Aslam, from Abdullah bin Abu Qatada, from his father, and he related it. Its chain of transmission is sahih. Ibn Hibban also narrated it by this same route in his Sahih (93).Abu Hasan Qattan, the narrator of Sunan Ibn Majah, said, Abu Hatim told us, saying, Muhammad bin Yazid bin Sinan Ruhawi told us, saying, Yazid bin Sinan, meaning his father, told us, saying, Zayd bin Abu Unaysa told me, from Fulayh bin Sulayman, from Zayd bin Aslam, from Abdullah bin Abu Qatada, from his father, who said, I heard the Messenger of Allah ﷺ, and he related something similar. Here he inserted "Fulayh bin Sulayman" between Zayd bin Abu Unaysa and Zayd bin Aslam. Ibn Khuzayma (2495) and Ibn Abdul-Barr in Jami Bayan Ilm (54) both narrated it likewise, both by way of Muhammad bin Yazid bin Sinan Ruhawi, with similar wording, except that Ibn Abdul-Barr worded it, "Three things continue to benefit the Muslim after his death, a charitable endowment he set in motion whose reward continues to reach him, a righteous child who prays for him, and knowledge he spread which is acted upon by those after him."Munziri graded the chain of this hadith sahih after attributing it to Ibn Majah. See Targheeb wal-Tarheeb (125, 188). If he meant by this the first narration, then he is correct, for its narrators are trustworthy. But if he meant the second narration, it contains Fulayh bin Sulayman, and although he is among the narrators found in the two Sahihs of Bukhari and Muslim, his memory has been called into question, and for this reason Hafiz said of him, "Truthful, but he made many mistakes."On this subject there is also a report from Abu Umama Bahili, from the Messenger of Allah ﷺ, that he said, "Four kinds of people continue to have their rewards flow to them after death, one stationed as a guard in the cause of Allah, one who did a deed whose like reward continues to be given to him, a man who gave charity whose reward continues for him as long as it continues to be spent, and a man who left behind a righteous child who prays for him." Imam Ahmad (22247) narrated it from Hasan, who said, Ibn Lahia told us, from Khalid bin Abu Imran, from Abu Umama Bahili, and he related it.Ibn Lahia is subject to well known criticism, and Khalid bin Abu Imran, who is Tujibi, did not hear directly from Abu Umama. For this reason Imam Ahmad also narrated it (22318) by another route from Abdullah bin Mubarak, from Ibn Lahia, from Khalid bin Abu Imran, from someone who related to him from Abu Umama Bahili, and he related it. But this unnamed man is unknown.The hadith has other routes weaker than this one. Likewise, what is reported from Samura bin Jundab is not sound, that he said, the Messenger of Allah ﷺ said, "No charity given by people equals knowledge that is spread." Tabarani narrated it in Kabir, and it contains Awn bin Umara, who is daif, as Haythami said in Majma (1/166).On this subject there is also a report from Anas and from Ibn Abbas, but the chains of both contain narrators who are discarded. See Majma al-Zawaid by Haythami.