0

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>

Edited by Aser Gado: n/a

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Aser Gado
0

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

}
0

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!");
0

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'>";
}
    ?>
0

hmm.

check through this:

$query=mysql_query("SELECT * FROM Persons WHERE Id ='$Id'");
if (mysql_num_rows($query)==0)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.