Staying hydrated with enough water and other hydrating drinks can help boost your immune system so yes drinking water may prevent you from getting the flu or other illness.
Being hydrated helps your body to help fight off viruses when they enter your body.
You should also drink orange juice or other juice that contains Vitamin C and eat fruits that contain vitamin c too since Vitamin C is an immune booster.
Always wash your hands often too to keep viruses off your body and prevent them from spreading to other people.