Every time I run this (with the querystring blank or set to some invalid text), the numrecs echo shows a value of 1 (and the code branches in that direction.) But in reality, there are ZERO records found.
If I copy the echoed query from the screen and paste it into phpMyAdmin, it returns "0". Can anyone spot the problem?
there should always be exactly one record returned, the record containing the number of matches. That number may well be zero, but you have to check the actual value, not the number of rows returned, to find out.