Getting water in a urine sample won't affect the actual detection of the presence of a drug (or whatever) but it will obviously affect the concentration of that substance.
For example, someone who has 120 mg of alcohol in 100 ml of urine (above the legal limit of 107 mg in England, Wales & NI), but who manages to dilute their urine sample with an equal quantity of water, will appear to only have 60 mg of alcohol per 100 ml of (diluted) urine.
When we were being taking urine tests while working on the railways, the tester would spend ages securely taping down the lids of all the WCs and taping up all of the washbasins (as well as taping all the windows shut, so that nobody could pass anything in or out) before instructing us to go into the loo to produce a sample. If they'd not done so, they'd have had no way of knowing whether the sample had been diluted or not.