This is a question that is deceptively hard to answer. Most students do not understand that plants use water, sunlight AND carbon dioxide to make sugar and produce oxygen. They consume the carbon from the air to make glucose as the product of photosynthesis with the biproduct being oxygen. Plants absorb water and nutrients from the soil, but do not get their food from the soil. They use the carbon dioxide in the air to make the carbon that is found in glucose. If you look at the following equation it will graphically explain what is being stated here.
CO2 + H2O -----sunlight--------> C6H12O6 + O2
It is also a common misconception that students do not understand that plants also undergo cellular respiration. So they not only produce oxygen, but they consume it as well. They make glucose in the process of photosynthesis and then break that glucose down in the process of respiration to produce ATP, an energy form, to grow and reproduce.
Hope this helps! Thanks for asking.