Have you tried running the query in phpmyadmin, or cpanel, etc?
Without knowing the tables and thier data, we are making assumptions. Assuming that all else is correct then the only SQL reason for that query to fail is because there are no member ids that match the referer ids. Try changing it to an explicit LEFT JOIN, then you will at least get the purchase info. If the member name is NULL then, yes, member id and referer id do not match.
$query = "SELECT purchaseinfo.*,members.Name FROM purchaseinfo LEFT JOIN members ON purchaseinfo.refer_id = members.ID";