-2

我正在创建一个函数,在插入用户名后将从数据库中检索用户显示图片。但我的代码遇到了一些问题。请帮我检查一下^^非常感谢。

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

$name = $_SESSION['login_username']; // login_username is test123, this is $_SESSION from another .php file
$_SESSION['name'] = $storename;


echo '<img src="display2.php"width="90" height="90"/>'; //this is how i display my picture
?>

Display.php(不工作)

mysql_select_db($database) or die("Can not select the database: ".mysql_error());

$storename = $_SESSION['name']; // is there an error with my $_session statement?
$name = (string)$storename; 

if(!isset($name) || empty($name)){
     die("Please select your image!");

}else{


$query = mysql_query("SELECT * FROM customerdetail WHERE customer_username='$name'");
$num_row = mysql_fetch_array($query);
$content = $num_row['image'];

header('Content-type: image/jpg');
echo $content;

 }
}   

Display.php(工作)

    $storename = "test123"; // it worked if i store the id in string but not passing from another page.
    $name = (string)$storename;

if(!isset($name) || empty($name)){
     die("Please select your image!");
}else{

$query = mysql_query("SELECT * FROM customerdetail WHERE customer_username='$name'");
$row = mysql_fetch_array($query);
$content = $row['image'];

header('Content-type: image/jpg');
         echo $content;

}
?>  

谁能帮我弄清楚出了什么问题?提前致谢。

4

2 回答 2

0

header('Content-type: image/jpg');声明输出将是 jpg 图像,因为代码从<img src="">

无法将文本显示为图像

于 2013-01-08T11:07:11.723 回答
0

在您的 php 文件(两者)的最顶部,放置这行代码(<?php当然,在标记之后):

session_start();
于 2013-01-08T11:50:35.603 回答