What I'm doing wrong? Is it impossible to being prompted when redirecting script like that?

Added:
I realized that my script have more problems (like using $USER variable, that is standard environmental variable), however my question really is about prompting. I reduced a problem to this simple script:

Everything is visible in cited code. I'm logging through SSH and trying to run commands from redirected content of script. One of those commands queries mysql, however instead of asking me for password, it just fails.
–
Łukasz ZarodaFeb 19 '14 at 17:28