I know what you're trying to do. I also know you can't do it if you don't initialize $row 😉
Here are the first 3 lines of your script:
$sql = "SELECT * FROM users WHERE uid = $uid";
$result = query($sql);
$app_id = $row['app_id'];
You've never had $row before that last line, and now you assign $app_id to be the value of something that doesn't exist. Do you see the problem now?
I'm thinking you wanted this:
$sql = "SELECT * FROM users WHERE uid = $uid";
$result = query($sql);
while ($row = some_function_that_makes_rows($res)) {
$app_id = $row['app_id'];
}
Of course, you have another problem. There's no function called [man]query/man, either.
Maybe trying reading a good tutorial?