a man was once in the Sacred Mosque—this was long ago—who wished to pray. When the iqāma was called he said aloud, “O Allah, I intend to pray Zuhr, four rakʿahs, for Your sake, behind the Imām of the Sacred Mosque.” Just as he was about to pronounce the takbīr, the man beside him whispered, “Wait—there’s still something left!”
“What is left?” he asked.
The neighbor replied, “Say: on such-and-such a day, on such-and-such a date of this month and year, so the record will not be lost. This is a document!”
The fellow was astonished—and with good reason. Are you informing Allah, Exalted is He, of what you intend? Allah knows what your own soul whispers. Will you inform Him of the number of rakʿahs and of the prayer time? There is no need; Allah already knows. Intention resides in the heart.
Now, as we know, prayers fall into three categories: unrestricted voluntary prayers, specified voluntary prayers, and obligatory prayers. The obligatory prayers are five: Fajr, Zuhr, ʿAsr, Maghrib, and ʿIshāʾ. If you come to the mosque at the time of Fajr, what do you intend to pray? Maghrib?! Of course not—Fajr. You arrive, raise the takbīr, and you certainly mean to pray, yet it may slip your mind that the prayer is Fajr.
A related question: suppose you enter, pronounce the takbīr, and it momentarily escapes you which prayer it is. This happens often, especially when someone rushes in for fear of missing the rakʿah. He arrives, joins the congregation, and says the takbīr without consciously recalling that he intends Fajr. In such a case there is no problem; the mere fact that the prayer is being performed in its appointed time is proof that he intended that very prayer. Therefore, were someone to ask you, “Did you mean Zuhr, ʿAsr, Maghrib, or…"