从mysql数据库显示图像的问题

时间:2013-03-14 06:35:33

标签: php mysql image

我已经在这个问题上工作了很长一段时间并且做过研究,但我没有

可以找到特定于我的问题。我正在为我的每个用户构建一个个人资料页面

在我们的网站注册。在此注册期间,用户添加配置文件数据以及

个人资料图片。用户登录确定并正确显示所有内容但显示

uploadimage它返回上传文件的名称而不是实际图像;

    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: test@yahoo.com</br>
    Profile Image: pic.jpg</br>
    Location: test, California 90100</br>

下面的登录代码。请帮忙!

    <?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;

2 个答案:

答案 0 :(得分:2)

将图片包装在img标记

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

还要确保src指向其所在位置image的路径。

答案 1 :(得分:0)

图像应始终显示在标记

替换

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

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

图像的路径应该是正确的。