The question of why do planets do not move out into space has been around for centuries, before for the first time around 1700 Sir Isaac Newton answered it. To do this he postulated that between any two masses `m_1` and `m_2` there is an attractive force that was named gravitatinal force. The absolute value of this force is
`F = G*(m_1*m_2)/R^2` (1)
Starting from this, he developed the entire Newtonian mechanics (as we learn it today) with its three principles and definitions about motion quantities as speed, acceleration, momentum and energy. In Newton vision the gravitational force is continuously curving the trajectory of a planet in its motion around a central star.
At the beginning of the last century, another brilliant scientist starting from new ideas has developed a new theory to explain why the planets do not move out into space. His name was Albert Einstein and the name of the theory was General Relativity. By observing that in the expression of the force above (1), at the denominator it is the square of distance `R^2` between two masses, and that the expression of a sphere surface area is `S =4*pi*R^2` his idea was that in fact the space itself is curved by the presence of a mass. It is like in the center of a 2D fabric representing the space, a big ball (the central star) is curving the fabric, and small balls (planets) just follow the curvature of the fabric in their linear motion (and thus a straight line becomes a closed circle). This is named in physics the principle of the smallest action, which any trajectory need to follow. Thus not the existence of a force is making the planets not to move out into space but the texture of the space itself.
according to newtons 1law every body in this universe tends to be in its state of uniform motion unless and until compelled by an external force
so planets should also be in continous straight line motion however ACCORDING TO NEWTONS UNIVERSAL LAW OF GRAVITATION every body attracts another body by a force that is given by f=GMm/r^2
so there exists a force of gravitation btwn earth/planet and sun this force keeps planets in their orbits however planets dont collide with sun because the above mentioned forces actually act as centipietal force(towards centre)and there is an opposite force generated to this force CENTRIFUGAL FORCE (away from centre) these forces balance each other in such a way that planet revolves in its orbital