prova aggiungendo apici singoli a $catSel:

Codice PHP:
$sql "SELECT foto_id,foto_nome,foto_size,foto_type, foto, foto_cat,foto_naz FROM img WHERE foto_cat = '".$catSel."'  ORDER BY RAND() LIMIT 2"
e lascia header ("Content-type: ".$type);

p.s. i tag per il php sono PHP non CODE