In German, if you are going somewhere (meaning a movement or motion involved – ‘Bewegung’) then it’s Akkusativ. But when you are already ‘at a place’ or doing something at a place it’s Dativ.
That’s why when you say – ‘I am going to school’ – it means a motion or movement - Akkusativ
On the other hand,
when you say – ‘I am at school’ – it means you are already ‘at this place or at school’. It doesn’t matter, what you are doing at school – may be you are learning at school or playing with other students at school – it’s always Dativ
Examples - Akkusativ
Ich gehe in die Schule – I go to school.
Er geht in die Schule – He goes to school.
Examples - Dativ
Ich bin schon in der Schule – I am already at school.
Ich lerne in der Schule – I learn at school.
Ich spiele in der Schule – I play at school.
Darf man in der Schule Handy benutzen? - Is it possible to use cell phone in school? (or May I use my cell phone at school?)
Darf man in der Schule Alkohol trinken? – Is it possible to drink alcohol in school?
Similar examples:
Er geht in den Garten – He goes into the garden (Akkusativ)
Er ist im Garten – He is in the garden (Dativ)
der Garten – garden (Plural form – die Gärten)
die Bewegung – motion, movement (Plural form – die Bewegungen)