1

I have been working on this issue for quite sometime and have done research but nothing I

can find was specific to my issue. I am building a profile page for each of my users they

register with our site. During this registration the user adds profile data as well as a

profile image. The user logs in ok and displays everything correctly but when displaying

the uploadedimage it returns the name of the file uploaded and not the actual image as such;

    Profile Page for testuser</br>
    Username: testuser</br>
    Name: testuser</br>
    Birthdate: January Day, 1980</br>
    Member Role: Tester</br>
    Genre: cool stuff</br>
    Personal Details</br>
    E-mail: [email protected]</br>
    Profile Image: pic.jpg</br>
    Location: test, California 90100</br>

login code below. Please help!

    <?php   
        $img_url = "uploads";

        //loginscript.php


        //check if variables were received
        if(($_POST['username']!=NULL) && ($_POST['password']!=NULL)):
        //if yes, proceed with script
        //get POST variables and use md5 for password encryption

        $uname = $_POST['username'];
        $pass = $_POST['password'];


        //connect to database
        $link = dbconnect();

        //check username validity
        $validUser = checkUsername($uname);

        //throw error on invalid username
        if(!$validUser){
        die('The specified user does not exist!');
        }

        //compare username/password
    $sql = "SELECT COUNT(*) FROM tbldatabase WHERE username = '$uname' AND password = $pass'";      
        $query = mysql_query($sql);                                                                              
        if(!$query){ die('MySQL failed with error: '.mysql_error());    }                               
        //throw error on username/pass mismatch
        if(!mysql_result($query,0,0)){                                                                  
                //if result < 1, username/password mismatch
                die('The password entered does not match test');
            }


            //validation successful, login (or just display info)
            $sql = "SELECT ID FROM tbldatabase WHERE username = '$uname'";                                  
            $query = mysql_query($sql);                                                                     
            if(!$query){ die('MySQL failed with error: '.mysql_error());    }                               
            $UID = mysql_result($query,0,0);                                                                


            $data = getTableData('tbldatabase',$UID);
            $uInfo =  mysql_fetch_array($data, MYSQL_BOTH);

            ?>
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"       
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title><?=$uInfo['username'] ?>'s Page</title>
            <style type="text/css">
            #apDiv1 {
    position: absolute;
    width: 200px;
    height: 115px;
    z-index: 1;
}
            #apDiv2 {
    position: absolute;
    width: 200px;
    height: 115px;
    z-index: 1;
}
            </style>
            </head>
            <body>
           <?php ?> <b>Profile Page for <?=$uInfo['username'] ?> </b><br />
            Username: <?=$uInfo['username'] ?><br />
          Name: <?=$uInfo['firstname'].' '.$uInfo['lastname'] ?><br />
      Birthdate: <?=$uInfo['bmonth'].' '.$uInfo['bdate'].', '.$uInfo['byear'] ?> <br />
            Member Role: <?=$uInfo['memberrole'] ?><br />
            Music Genre: <?=$uInfo['genre'] ?><p />
            <p><b>Personal Details</b><br />
            E-mail: <?=$uInfo['email'] ?><br />
            Profile Image: <?=$uInfo['Image'] ?><br /> 
    Location: <?=$uInfo['city'].', '.$uInfo['state'].' '.$uInfo['zipcode'] ?><?php ?>
            </p>
            <p>&nbsp;</p>



            </body> 
            </html>
        <?
        else: 
   die('necessary information requested from profile page is missing or omitted');

        endif;
4
  • Please remove all the extra code, only include the code related to the problem. I give you a hint: Show the code where the uploaded image is saved to database. Then show the code where it is read from database. And then finally show the code where the image is shown to the user. Commented Mar 14, 2013 at 6:50
  • //Form where image is being uploaded <div class="fieldWrapper"> <td>&nbsp;</td> <td>Profile Image</td> <td><input type="file" name="Image" id="Image" /> <input type="submit" name="Upload" id="Upload" value="Upload" /></td> </div> </div></tr> //Processed and sent to DB $Image = ($_FILES['Image']['name']); $query = "INSERT INTO tbldatabase (ID , firstname , lastname , Image) VALUES (NULL, '$firstname' , '$lastname' , '$Image')"; Commented Mar 15, 2013 at 7:28
  • e//Login process and query to DB $sql = "SELECT ID FROM tbldatabase WHERE username = '$uname'"; //build SQL query to get relevant ID $query = mysql_query($sql); //query database if(!$query){ die('MySQL failed with error: '.mysql_error()); } //else return error $UID = mysql_result($query,0,0); //get user ID //get info for specified user $data = getTableData('tbldatabase',$UID); $uInfo = mysql_fetch_array($data, MYSQL_BOTH); ?> Commented Mar 15, 2013 at 7:29
  • //Display Table Data\ <?php ?> <b>Profile Page for <?=$uInfo['username'] ?> </b><br /> Username: <?=$uInfo['username'] ?><br /> Name: <?=$uInfo['firstname'].' '.$uInfo['lastname'] ?><br /> Profile Image: <?=$uInfo['Image'] ?><br /> //I can look into mysql and see the image in my database but when I recall image it just displays file name and not the actual image Commented Mar 15, 2013 at 7:29

2 Answers 2

2

wrap image inside img tag

<img src="<?=$uInfo['Image'] ?>" alt="" />

also make sure src pointing to the path of image where its located.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the assistance as I have been really bumping my head on this. I made the change as requested to include the src of the image with a path i can get to via the url. However, I now only see a blank image where as in the browser I see a real image. Below includes my changes; Profile Image: <img src="mysite.com/uploads/"<?=$uInfo['Image'] ?>" alt='no image available'><br />
0

The image should always shown in tag

Replace

  Profile Image: <?=$uInfo['Image'] ?><br /> 

with

  Profile Image: <img src="<?=$uInfo['Image'] ?>" alt='no image available'><br /> 

And the path of the image should be correct.

6 Comments

thanks for the assistance as I have been really bumping my head on this. I made the change as requested to include the src of the image with a path i can get to via the url. However, I now only see a blank image where as in the browser I see a real image. Below includes my changes; Profile Image: <img src="mysite.com/uploads/"<?=$uInfo['Image'] ?>" alt='no image available'><br />
@phpapprentice hey change this to <img src="mysite.com/uploads/<?=$uInfo['Image'] ?>" alt='no image available'><br /> and try once again... and just to confirm what value are you getting in $uInfo['Image'].. ?
I received the exact same issue with the image appearing to be almost like an image place holder. You know there should be an image there but nothing displaying
Will I need to add an extension of the file like jpg,png etc?
will that be in the img src path? can you please post an example please?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.