This appears to be happening on a custom page of yours? If so the problem is that # (as well as $ and ^) have special meaning in queries passed to qa_db_query_sub(...) so you should use parameter substitution rather than concatenation to build the query.