通过会话PDO查询数据库 [英] PDO Querying database through sessions
问题描述
我正在尝试从数据库中调用数据以显示在用户个人资料上.我在检查用户文件中使用户会话正常工作.但是下面的代码显然是;检索任何内容,因为它不会在我的HTML中的echo语句中回显.有人可以帮忙吗???
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();
}
}
推荐答案
因为要从所谓的代码"混乱中分辨出您要做什么是绝对不可能的-因此,只为您提供有关代码的想法需要基于存储在会话中的ID从数据库获取用户详细信息:
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();
在$ user数组中,您应该使用bio和stuff的名称.检查会话变量名称
here in the $user array you should have name bio and stuff. Check session variable name
这篇关于通过会话PDO查询数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!