set scope on variable
solved query and fixed the if statement redirection