This error occurs because your ArtistName recordset is inside of a repeat region... so if there are no results the recordset doesn't end up being created.
The solution is probably to move the mysql_free_result() line from that recordset inside of the repeat region as well.
So move this line:
mysql_free_result($ArtistName);
inside of the repeat region just before line 335