我正在处理个人资料页面。我想为尚未上传个人资料图片的用户设置默认图片。但是,图片无法显示。它显示了一个破裂的图像。为什么呢?
这是我的代码。
<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 的类似问题,并且也尝试了这些方法。然而无济于事。需要很多帮助。谢谢。
PS我对php和mysql的了解有限。