gpt4 book ai didi

php - $_Session 没有收集所有用户信息?

转载 作者:搜寻专家 更新时间:2023-10-30 23:09:46 26 4
gpt4 key购买 nike

目前在用户网站上工作,使用这段代码遇到了一些问题:

 <?php 

// Connects to your Database
mysql_connect ("host","a2530897_admin","pass") or die("Could not conenct");
mysql_select_db("a2530897_members") or die ("could not connect to dadabase!");

$SQL=mysql_query("SELECT * FROM users WHERE username='".$_SESSION['username']."'")
or die(mysql_error());
session_start();

echo "<strong>First Name: ". $_SESSION['first_name']."</strong>";
echo "<strong>Last Name: ". $_SESSION['last_name']."</strong>";
echo "<strong>Email Name: ". $_SESSION['email_address']."</strong>";
echo "<strong>Photo: ". $_SESSION['photo']."</strong>";
echo "<strong>Username: ". $_SESSION['username']."</strong>";
echo "<strong>Date: ". $_SESSION['date3']."</strong>";

?>

这似乎可以正确显示大部分信息,名字、姓氏和电子邮件地址都可以。当我尝试调出与用户信息一起输入的照片名称、用户名或日期时,它没有出现并且显示为空白?有谁知道我可能做错了什么?

最佳答案

您在开始 session 之前使用 session

$SQL=mysql_query("SELECT * FROM users WHERE username='".$_SESSION['username']."'") 
or die(mysql_error());
session_start();

应该是

session_start();
$SQL=mysql_query("SELECT * FROM users WHERE username='".$_SESSION['username']."'")
or die(mysql_error());

根据用户名,您正在为该用户获取记录,然后无需显示 session 变量中的信息,您可以直接显示如下

session_start();
$SQL=mysql_query("SELECT * FROM users WHERE username='".$_SESSION['username']."'")
or die(mysql_error());

$row = mysql_fetch_array($SQL);

echo "<strong>First Name: ". $row['first_name']."</strong>";
echo "<strong>Last Name: ". $row['last_name']."</strong>";
echo "<strong>Email Name: ". $row['email_address']."</strong>";
echo "<strong>Photo: ". $row['photo']."</strong>";
echo "<strong>Username: ". $row['username']."</strong>";
echo "<strong>Date: ". $row['date3']."</strong>";

关于php - $_Session 没有收集所有用户信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21677992/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com