dongpochi9741 2014-07-21 12:53 采纳率: 100%
浏览 50

访问会话数据以查询DB以获取其他数据

So when a user logs into my site, I pull the user ID from the users table and save it in the session. THis works i've tested it by using

echo "test" . $_SESSION['UserID'];

this displays the current user ID now how do I use $_SESSION['UserID'] in a mysql query to get a number from a different table which has user ID as a foreign key?

Apologies if this seems stupid, first time dealing with sessions

  • 写回答

1条回答 默认 最新

  • dongshu4755 2014-07-21 13:01
    关注

    You can directly hold the value of $_SESSION['UserID'] into a variable and use it like a normal PHP constructs.

    Perhaps one of the way:

    if(isset($_SESSION['UserID'])) {
        $userId = $_SESSION['UserID'];
        $sql= 'select * from user_addresses where UserID = '.$userId;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用