从数据库中选择数据并不起作用

时间:2016-12-28 11:13:32

标签: php mysql pdo login

我做了一个注册和登录表单,用户可以在其中添加个人资料照片。当他们登录时,他们被重定向到dashboard.php。在那里,我想向他们展示他们的名字和个人资料照片,但仅限活跃用户。

此刻,这是我的代码:



<?php
session_start();
require_once 'header.php';
/*Veradneren + aanpassing navigatie.php*/
$current = 'dashboard.php';
require_once 'navigatie.php';
function getImage()
{
    require "connectie.php";
    $user = $_SESSION["username"];
    try {
        $stmt = $db->prepare("SELECT * FROM gebruiker WHERE username = $user");
        $stmt ->bindParam("username",$user);
        $stmt->execute();
        $results = $stmt->fetchAll();
            return $results;
    }

    catch (PDOException $e) {
        $message = $e;
    }
}
?>

<main>
<div class="container">
    <?php echo $message;?>
    <div class="row">

        <h1 class="center-align"><?php echo "Welkom, " . $_SESSION["username"];?></h1>
            <?php
                $results = getImage();
                foreach ($results as $row){
                    echo "<img class='' 
                                src='uploads/{$row['profilepic']}'
                                 alt='Alternatief profiel foto'>
                        ";
                } ?>


    </div>
</div>
</main>
<?php require_once 'footer.php'; ?>
&#13;
&#13;
&#13; 数据库结构: Database 图片上传到文件夹上传

0 个答案:

没有答案