<?php
    include ("connect.php");
    $_SESSION['username']="kai";
    $username=$_SESSION['username'];
    echo "Welcome,".$username."!<p>";
    $query= mysql_query("Select * from avatar where name = 'username'");

    if(mysql_num_rows($query)==0)
        die("User not found");
    else
    {
        $row = mysql_fetch_assoc($query);
        $location = $row['imagelocation'];
        echo "<img src='$location' width='200' height ='200'>.</p>";
    }
?>
<p/> Upload New Avatar
<form method="post" enctype='multipart/form-data' action='view.php'>
    File: <input type='file' name='myfile'>
    <input type='submit' name = 'submit' value='UPLOAD'>
</form>

mysql_query() returns a resource on success, or FALSE on error. So better if you can check for that before calling mysql_num_rows()

if($query)
{
    if(mysql_num_rows($query)==0)
    {
        die("User not found");
    }
    else
    {
        $row = mysql_fetch_assoc($query);
        //other code
    }
}
else
{
    die("Invalid Query");
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.