How do the planets stay in orbit around the sun?

The Solar System was formed from a rotating cloud of gas and dust which spun around a newly forming star, our Sun, at its center. The planets all formed from this spinning disk-shaped cloud, and continued this rotating course around the Sun after they were formed. The gravity of the Sun keeps the planets in their orbits. They stay in their orbits because there is no other force in the Solar System which can stop them.