PDO Querying database through sessions

冷暖自知 提交于 2019-12-25 16:44:56

问题


I am trying to call data from my database to display on a users profile. I have the user session working correctly in the check user file. However the code below obviously isn; retrieving anything because it won't echo out in the echo statment i have in my HTML. Can someone please help???

require_once 'check.php';

if(isset($_GET['full_name'])){
    $full_name = $_GET['full_name'];
    $username = $_GET['username'];
    $country = $_GET['country'];
    $bio = $_GET['bio'];
    $stmt = $dtb->prepare(" SELECT full_name=:full_name, username=:username, country=:country, bio=:bio FROM users WHERE id=:log_user_id AND username=:log_uname LIMIT 1");
    $arr = array(
        "full_name"     =>  $full_name,
        "username"      =>  $username,
        "bio"           =>  $bio,
        "country"       =>  $country,
        "log_user_id"   =>  $log_user_id,
        "log_uname"     =>  $log_uname
    );
    ArrayBinder($stmt,$arr);
    try{
        $stmt->execute();
        $dtb = null;
        exit();
    }
    catch(PDOException $e){
        echo $e->getMessage();
        $dtb = null;
        exit();
    }
}

回答1:


As it's absolutely IMPOSSIBLE to tell what are you trying to do from that mess you called "code" - so, just to give you an idea on the code you need to get user details from database based on id stored in a session:

$sql = "SELECT full_name,username,country,bio FROM users WHERE id=?";
$stmt = $dtb->prepare($sql);
$stmt->execute([$_SESSION['log_user_id']]);
$user = $stmt->fetch();

here in the $user array you should have name bio and stuff. Check session variable name



来源:https://stackoverflow.com/questions/22987841/pdo-querying-database-through-sessions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!