Step-by-step explanation:
I haven't studied this in quite a long time but I will try my best to answer your question.
Gravity is a force that pulls things towards it and everything has gravity. The larger an object the stronger it's force of gravity and the more it pulls objects towards it. In our solar system the Sun is the largest object (by far) and therefore has the highest gravity. This means that the planets orbit the sun since the gravity of the sun is pulling the planets towards it. This stops planets from flying to outer space.
The thing that stops the planets from crashing into the sun is that they are travelling too fast. The planets are trying to travel in a straight direction, but the gravity and their speed in another direction kind of counteract and create a "medium" I guess you could call it, meaning the planet just orbits the sun.