Hai dimenticato di chiudere bene
Prova cosìcodice:$ris = mysql_query(" SELECT forummesxp FROM infame WHERE id IN (SELECT foto FROM presenti WHERE ip='".$ip."' and logout=0 order by id desc)",$conn) ) or die("Errore nella query3: " . mysql_error());