upload profile image but upload only ram user pic .other user not able to upload there image .how to define every user has upload there prof. image . anyone help me for this problem

// Upload Form
<?php
include("connect.php");

$_SESSION['username']= 'ram';
$username=$_SESSION['username'];

if(isset($_POST['submit']))
{
        //get file attributes

        $name=$_FILES['myfile']['name'];
        $tmp_name=$_FILES['myfile']['tmp_name'];

        if($name)
        {
                //start upload process

                $location="$name";
                move_uploaded_file($tmp_name,$location);
                $query=mysql_query("UPDATE members SET imagelocation='$location' WHERE username='$username'");
                die("Your Avatar has been uploaded!! <a href='view.php'></a>");
                
        }
        else
        {
                echo "Please upload a file";
        }       
}




echo "upload image: <br>

<form action='upload.php' method='POST' enctype='multipart/form-data'>

File:<input type='file' name='myfile'><input type='submit' name='submit' Value='Upload'
</form>

";



?>

//View  Form

<?php
require("connect.php");
 
$username=$_SESSION['username'];
$query=mysql_query("SELECT *FROM members WHERE username='$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='100' height='100'>";
}
?>

In line no 5 the $_SESSION["username"] is always set to "Ram". Thats why the problem. Please check that line.

In line no 5 the $_SESSION["username"] is always set to "Ram". Thats why the problem. Please check that line.

when i removing the user session ram can't upload image in my user table.
how to set any user has login and update image

you have to set that in your login page when the user login...

'session_start()' requires on your page. But, it might be the first before output any HTML or processing PHP codes.

<?php
session_start();
?>
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.