in reply to Record Count
how about doing a select count(*) from affiliate where affiliate_number = '$an'
if the count is zero, then there's no matching affiliate.
Also, depending on your dbms, leaving the $an unquoted in your select statement may cause a syntax error if $an happens to be undefined.
I like chicken.