Here are the errors:
mysql_query( 'SELECT uid
FROM hostedgals_cats c
WHERE c.name LIKE \'' . $termnos . '\' or c.name like \'' . $termwiths . '\'' );
$getuidsfromcats = ;
mysql_query( 'SELECT cat_id
FROM category_matches m
WHERE m.name LIKE \'' . $termnos . '\' or m.name LIKE \'' . $termwiths . '\'' );
$getuidsfrommatchcats = ;
You should be assigning those variables with the results of the calls, so it they should be:
$getuidsfromcats = mysql_query( 'SELECT uid
FROM hostedgals_cats c
WHERE c.name LIKE \'' . $termnos . '\' or c.name like \'' . $termwiths . '\'' );
$getuidsfrommatchcats = mysql_query( 'SELECT cat_id
FROM category_matches m
WHERE m.name LIKE \'' . $termnos . '\' or m.name LIKE \'' . $termwiths . '\'' );