PHP returning 'undefined' from mysql

I can’t for the life of me figure out what’s going wrong here, and I’m not well versed in mysql so I feel like it’s something simple…

here’s my php file:


<?php
    $connection=mysql_connect("localhost","nt","1013433D7") or die(mysql_error());
    mysql_select_db("Doors_Database") or die(mysql_error());

    if ($_POST['sendRequest'] == "top5") {
        
        $level=$_POST['currentLevel'];
        $myFile="output.txt";
        $fh=fopen($myFile,'w');
        fwrite($fh,"inside top5 request
");
            
        
        $fp="SELECT username FROM hiscores WHERE level=".$level." ORDER BY score ASC LIMIT 1";
        fwrite($fh,$fp."  request made.
");
        $result=mysql_query($fp);
        if($result){
            fwrite($fh,"users returned");
        }
        else{
            fwrite($fh,"users not retured");
        }
        
        $r1=mysql_fetch_assoc($result);
        $rl=$rl['username']
        


        print "var1= $r1";
        print "&var2= $r1";
        print "&var3= $r1";
        print "&var4= $r1";
        print "&var5= $r1";
    }//END OF REQUEST FOR TOP 5 PLAYERS
    
    mysql_close($connection);
?>

nothing gets printed to a file, and the flash application receives ‘undefined’ from the php file…