How do you stop the water from flowing in an upstairs bathroom when the hot and cold knobs are turned off?

You need to turn it off at the base of the sink. Or depending on the problem you may need to turn it off at the water main valve.