$fname = mysql_query("SELECT fname FROM student_reg WHERE username='$username'");
you are making a mysql_query -> and save the result int $fname.
then you trigger a mysql_query from the result you got from the sql query:
the code should look like that:
//make a sql_query and save the result from that into $result
$result= mysql_query("SELECT `fname` FROM `student_reg` WHERE `username` = '$username'");
//next we need to fetch the data out of our result. Now it depends on what you want to do next with the data you received. Any of the below code could be right - depending on your what you wanna do with it
$array = mysql_fetch_array($result); //would save result in a array
$object= mysql_fetch_object($result); //would save it into a object
$associativeArray = mysql_fetch_assoc($result);
$field = mysql_fetch_field($result); //get a single field
//next give out e.g.
Read that up on php.net or elsewhere ;) Then you understand best...
Your error means simply that you dont have an string available - so you cannot print/echo it