I bought an electro magnet and i have some questions
The 9V battery can't supply the current you need for the electromagnet, at least not for a long time; it is too small. The voltage will drop almost immediately, and it won't last long.

The electromagnet has a coil, an inductance, and there will be a kickback when you disconnect it. You will need a diode you mention to protect the rest of the circuitry.

Not a good plan; voltage dividers don't make good power supplies, and neither do 9V batteries for anything else than very small currents.