我正在处理个人资料页面。我想为尚未上传个人资料照片的用户设置默认图片。但是,无法显示图片。它显示了破裂的图像。为什么会这样?
这是我的代码。
<html>
<head>
<title>User Profile</title>
</head>
<body>
<?php
include ('connect.php');
if (isset($_GET['id'])) {
$id = $_GET['id'];
mysql_connect("localhost", "root", "") or die ("Could not connect to the server");
mysql_select_db("userprofile") or die ("Invalid database!");
$userquery = mysql_query("SELECT * FROM userprofile WHERE user_id = '$id'") or die ("The query could not be completed");
while ($row = mysql_fetch_array($userquery)) {
$id = $row['user_id'];
$username = $row['user_name'];
$firstname = $row['first_name'];
$lastname = $row['last_name'];
$email = $row['email'];
$description = $row['description'];
$image = $row['image'];
}
if (empty($image)) {
$image = "avatardefault.png";
}
?>
<h2><?php echo $firstname; ?> <?php echo $lastname; ?>'s Profile</h2><br />
<table>
<tr><td>Username: </td><td><?php echo $username; ?></td></tr>
<tr><td>Firstname: </td><td><?php echo $firstname; ?></td></tr>
<tr><td>Lastname: </td><td><?php echo $lastname; ?></td></tr>
<tr><td>Email: </td><td><?php echo $email; ?></td></tr>
<tr><td>Description: </td><td><?php echo $description; ?></td></tr>
<tr><td>Image: <img src = "/avatars/'.$image.'" width = "200px" height = "200px"></td></tr>
</table>
<?php
} else die ("You will need to specify a id!");
?>
</body>
</html>
我已经阅读了有关stackoverflow的一些类似问题,并且还尝试了这些方法。但无济于事。需要很多帮助。感谢。
P.S我对php和mysql的了解有限。
答案 0 :(得分:1)
这不在<?php ?>
块内:
<img src = "/avatars/'.$image.'"
所以它应该是:
<img src = "/avatars/<?php echo $image; ?>"
答案 1 :(得分:0)
您的代码:
<img src = "/avatars/'.$image.'" width = "200px" height = "200px">
你忘记了。$ image周围的PHP标签。部分。它应该是:
<img src = "/avatars/<?php echo $image; ?>" width = "200px" height = "200px">