Here, the difference is not between gender: 'Stadt' is always a feminine noun. Here, 'in der Stadt' is in the dative case, governed by the preposition 'in', whilst 'in die Stadt' is in the accusative. 'In' is part of a group of prepositions that can either take the dative or the accusative, depending on whether movement is involved or not. Where you can translate 'in' as 'into' as in the second sentence - I drive in OR into the city - there is movement involved, and 'in' takes the accusative. Where you can translate 'in' as 'inside', as in the first sentence, there is no movement, and thus the dative is used - I drive in/inside the city. Another example would be the pair of sentences 'ich lege es auf den Tisch' and 'es liegt auf dem Tisch'. In the first sentence, there is movement - the speaker is placing something down onto the table, and the accusative is therefore used. In the second sentence, there is no movement, since the thing is just lying on the table, meaning the dative is used.