【发布时间】:2017-12-13 11:51:10
【问题描述】:
我在尝试检索存储在 MYSQL 数据库中的用户配置文件链接时遇到问题。
我尝试运行此代码来选择用户配置文件(存储用户配置文件图片链接的位置),但出现 500 错误。
<?php
$stmt = $DB_con->prepare('SELECT id, userprofile FROM users ');
$stmt->execute();
if($stmt->rowCount() > 0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
?>
链接存储在 userprofile 列中。
HTML(function.php 中有数据库信息):
<?php
include('functions.php');
if (!isAdmin()) {
$_SESSION['msg'] = "You must log in first";
header('location: ../login.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<title> Admin Home</title>
</head>
<body>
<div class="header">
<h2>Admin - Home Page</h2>
</div>
<div class="content">
<!-- notification message -->
<!-- logged in user information -->
<div class="profile_info">
<img src="uploads/<?php echo $row['userprofile']; ?>" class="img-rounded" width="250px" height="250px" />
<div>
<?php if (isset($_SESSION['user'])) : ?>
<strong><?php echo $_SESSION['user']['username']; ?></strong>
<small>
<i style="color: #888;">(<?php echo ucfirst($_SESSION['user']['user_type']); ?>)</i>
<br>
<a href="home.php?logout='1'" style="color: red;">logout</a>
<a href="create_user.php"> + add user</a>
</small>
<?php endif ?>
</div>
</div>
</div>
</body>
</html>
测试用户登录的图片(Bigfella)
关于为什么它没有从数据库中检索图像链接的任何想法?提前致谢!!
【问题讨论】:
-
保存用户头像
UserId.jpg。然后你可以运行if(file_exists('UserId.jpg'){ $profpic = 'UserId.jpg';} else {$profpic = 'defaultprofpic.jpg'}你不想和sql兄弟