Pilot light lights but goes out when i turn valve to on

Near the pilot there should be a small metal bulb at the end of what looks like a wire which leads back to the control valve. It's called a thermocouple and it produces a small electrical current when heated. Non-electric heating units have a similar device which does the same job using pressure produced by heating a fluid within the bulb but for our purposes here the difference between the two doesn't matter. The function of the thermocouple is to hold the gas valve open for normal operation of the pilot. If the pilot flame goes out the thermocouple cools and disables the valve so that when the thermostat calls for heat, the gas will not be released if there is no pilot to light the burner. Check to make sure the bulb is being heated by the pilot flame, it may need to be repositioned or the pilot may need to be cleaned of carbon buildup to make it produce an adequate flame. If the thermocouple is close enough to an adequate pilot flame and still you cannot sustain the pilot flame when going from "pilot" to "on" position, the thermocouple is probably the problem so replace it. If the problem still exists, assuming you have already made certain that you have an adequate fuel supply, the problem is in the burner control valve. Changing that is something you should consider leaving to a qualified service person.