After successfully creating a Registration/Signin/user profile... now I am assigning a profile picture for a user ... I have a question... Everytime I hit upload it doesnt upload I added an "echo' to say if no file is chosen "Please Select a file", it shows this even when I select a file.. here is my code:

<?php
Session_start();
include("database.php");

$Id = $_SESSION['Id'];
$sql=("SELECT * FROM Persons WHERE Id ='$Id'");
$result=mysql_query($sql);
$data = mysql_fetch_array($result);
  $_SESSION['Id'] = $data['Id'];
  $_SESSION['Email'] = $data['Email'];
  $_SESSION['FirstName'] = $data['FirstName'];
  

if ($_POST['submit'])
{
    $name = $_FILES['myfile']['name'];
    $tmp_name = $_FILES['myfile']['tmp_name'];
    
    if ($name)
    {
       //start upload
       $location = "avatars/$name";
       move_uploaded_file($tmp_name,$location);

       $query = mysql_query("UPDATE Persons SET imagelocation='$location' WHERE Id ='$Id'");
   
       die("Your Profile Picture has been uploaded! <a href='member.php'>Back to Profile</a>");



    }
    else
    die("Please Select a File!");




}

echo "Welcome, ".$_SESSION['FirstName']."!<p>";

echo "Upload Your Profile Image:";
?>
<HTML>
<Body>
<form action="upload.php" method="POST" ectype="multipart/form-data">
File: <input type="file" name="myfile">
<input type="submit" value="Upload!" name="submit">

</form>

<Body/>
</HTML>

Just to double check, the file you posted is called upload.php, as that is where your form data is being posted. If so, change the submit button code to the following and report back:

if ( isset($_POST['submit']) ) {
   
    $name = $_FILES['myfile']['name'];
    $tmp_name = $_FILES['myfile']['tmp_name'];
    $location = "avatars/$name";
    move_uploaded_file($tmp_name,$location);
    $query = mysql_query("UPDATE Persons SET imagelocation='$location' WHERE Id ='$Id'");
    
    echo $_FILES['myfile']['error']; //the error message returned

}

or try this:

[B] if ($name!="")[/B]
    {
       //start upload
       $location = "avatars/$name";
       move_uploaded_file($tmp_name,$location);

       $query = mysql_query("UPDATE Persons SET imagelocation='$location' WHERE Id ='$Id'");
   
       die("Your Profile Picture has been uploaded! <a href='member.php'>Back to Profile</a>");



    }
    else
    die("Please Select a File!");

Fixed, Thanks...One more questions, now since I have uploaded the picture to the database I am using this code to show it in the members profile:
BUT, It keeps saying "User not found" although I viewing the member page using the session!

<?php
      include("database.php");

 $Id = $_SESSION['Id'];
$query=("SELECT * FROM Persons WHERE Id ='$Id'");
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'>";
}
    ?>

hmm.

check through this:

$query=mysql_query("SELECT * FROM Persons WHERE Id ='$Id'");
if (mysql_num_rows($query)==0)

Fixed, thanks for the help :D

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.