Hey Dan!
If I were you, first of all i would try the mysql_error([db link identifier]) function, which tells you exactly what the mysql error is caused by.
Just a quick look at your code, tells me that this part of the code is not optimal:
else
{
$user = mysql_result($result,$i,"user");
$pass = mysql_result($result,$i,"pass");
$level = mysql_result($result,$i,"level");
When accessing the variable in which data returned from the mysql query, I usually use "$row = mysql_fetch_array($query_result)". Then you can access each variable int the array returned in $row, by typing $row[usrname] for example.
I hope that was of some help... - Mikkel