In the early morning of creation there were only stars and vast stretches of plasma (unconsolidated, primordial atoms in ionic state. Don't even bother if you don't understand that. You will still understand the main issue). The thing with stars is that they are such simple structures - they are made of the simplest atom that can ever be - hydrogen. Now, because they are so big (some are billions of times bigger than the earth), their weight is focused upon a centre so that they take the shape of a ball. All really big strictures must collapse upon itself to take the shape of a sphere or ball (the sphere is the most efficient use of resources when you need to balance volume with area in a three-dimensional space). Now, with this shape, the centre bears the brunt. It carries all the weight. It is like balancing a 500-storey building upon the point of a pen. That point will instantly become superheated and burst into flames. When hydrogen is overpressured at the centre of these stars, it doesn't just ignite, it undergoes what is called fussion, the extraordinary nuclear combination of a pair of its atoms. That's outright alchemy really. It is like turning water to steel!
Now, if hydrogen atoms weighing, let's say 10 grams fuse, we should expect 10grams of the product, names helium. But what happens is, we get just 9 grams of helium. What happens to the balance 1g? It vanishes completely, turning itself to tremendous heat without smoke or ashes! That's how stats burn so brightly and for billions of years give off extraordinary light and heat. The closest star to us is the sun and every second, it burns 600 billion tons of hydrogen.
The hydrogen in these stars is limited and the day comes that they are exhausted. One of the use of the heat produced by these stars is that it keeps the star from falling completely upon itself like a poorly baked cake. It sort of push stuff out in all directions (he light generated in the centre of the sun shoots out towards the surface and it takes it 8 years to make a full trip to the surface and start streaming down into space, meaning, the light of the sun you are perceiving at this moment was made eight years ago in the centre of the sun). When the hydrogen fuel finishes, heat production stops and what happens? The remaining helium collapses violently inwards, striking the centre of the dead star at once. This extraordinary implosive violence causes another nuclear reaction: another level of fusion, now, of helium atoms. The bigger the dead star, the more robust and powerful the fusion. Really big stars generate enough pressure during this helium collapses that they fuse their helium into a vast range of elements: oxygen, carbon, iron, gold, silicon and so forth. This of course goes with monstrous explosions - and planets are formed. There is a case of such a fusion that formed a planet that's entirely a solid block of diamond. Billions of tons of diamonds - it's out there floating, spinning and revolving around its parent.
So, this is how planets are formed and the bodies of living things, ours inclusive subsequently formed from a complex biochemical synthesis from the products of elements produced at the final death of stars. Some of the fragments of solid elements formed at the death of huge stars scatter to become asteroids and vast stretches of dust in the interstellar spaces. Some are in form of nebulae, which are unconsolidated planets in some cases.
It is possible the collapse of the same massive star formed the four rocky planets of the solar system and all the moon's (Moon, Io, Garymede, Titan, etc). So their composition will be similar after you have made allowances for forces that have shaped them further over the aeons of years. All the other planets in the solar system after the four that are closest to the sun (Mercury, Venus, Earth and Mars) are gas balls. They could be failed stars or dead, exploded small stars whose gravitational collapse could not generate enough fussion power to produce solid elements. They are mostly made of methane, carbon dioxide, oxides of nitrogen, helium and so forth.
Let us close by saying that water is not one of the things formed by the fusion of helium in collapsed stars. Water formed differently and it was brought to earth through comets, but that's a different level of cosmology.