I would make this easier to understand by separating the sql stuff from the display of the results. No need to intermingle this stuff.
As for your update query it looks flawed. Why are you selecting the record using where outstanding bal=..... when your first query only selected based upon the user name?
What problem are you having anyway? You didn't say, you just asked for help.