When electric current flows through a wire, a magnetic field is produced around the wire. You can detect this magnetic field on a straight wire, but when you coil the wire around a core, the magnetic fields of the wire-coils overlap and add, so the magnetic force intensifies. This produces an electromagnet.