Denis,
I would actually try to make this comparison inside the SQL statement if possible. First, generate everything with the wizard... then go back and hand code the comparison into the SQL using the "WHERE" clause." Then beneath that, you can a conditional PHP logic that states if no record shows up after you created the WHERE clause, then you know that the user doesn't qualify for site entry and then create a redirect.
If you use the wizard and post your code, I can help you about a bit more... I will be in and out the rest of the day but will do what I can.
Cheers,
Brian