gpt4 book ai didi

php - 显示 MYSQL 结果时出现问题

转载 作者:行者123 更新时间:2023-11-30 00:57:58 25 4
gpt4 key购买 nike

我正在尝试从数据库中检索当前登录我网站的用户的整行数据。然后,我想获取数据并将每个字段存储到一个变量中,这样我就可以调用这些变量中的任何一个,并在我需要的任何时候将其显示在页面上的任何位置。我遇到的问题是我不断收到以下错误

ERROR

Notice: Undefined variable: User_Info in C:\wamp\www\PhotographyConferenceSite\Users\account.php on line 129

第 129 行是我尝试测试代码并调用要打印的单个变量的位置。它说变量尚未定义,但情况不应该是这样。

这里是 PHP 代码:

if (isset($_SESSION['username'])) // This section is working I included it to show where my variable in my query is created.
{
$curUser = $_SESSION['username']; // curuser is valid as it is called on my html page and it works properly
$titleMessage = "You are logged in as: ";

$topNavSlot1Txt = "<li> Logout </li>";
$topNavSlot1Link = "../Login_System/logout.php";
}
else
{
header('Location: ../Login_System/login.php');
}

//CALLS DATA FOR THE ARRAY/GIVE ITS CONDITIONS
$user_data ="SELECT `User_Name`, `Email`, `First_Name`, `Middle_Initial`, `Last_Name`, `Phone`, `Cell_Phone`, `Address_1`, `Address_2`, `City`, `Zipcode`, `State`, `Country`, `Attendee`, `Referred_By`, `Skill_Level`, `Club_Member`, `Club_One`, `Club_Two`, `Club_Misc`, FROM `members` WHERE User_Name='$curUser'"; // where condition is calling a session vairable

$UDD = mysqli_query($db_server, $user_data);

if($UDD)
{
while( $User_Info = mysqli_fetch_array($UDD)) // Sets the retrived data to an array
{
// declares the arrays variables

$User_Info['User_Name'];
$User_Info['Email'];
$User_Info["First_Name"]; // THIS IS WHAT I'M TRYING TO TEST.
$User_Info['Middle_Initial'];
$User_Info['Last_Name'];
$User_Info['Phone'];
$User_Info['Cell_Phone'];
$User_Info['Address_1'];
$User_Info['Address_2'];
$User_Info['City'];
$User_Info['Zipcode'];
$User_Info['State'];
$User_Info['Country'];
$User_Info['Attendee'];
$User_Info['Referred_By'];
$User_Info['Skill_Level'];
$User_Info['Club_Member'];
$User_Info['Club_One'];
$User_Info['Club_Two'];
$User_Info['Club_Misc'];
}
}

这是我的 HTML 代码:

  <div id="accountInfo"> <!-- info for registration. -->
Did you change your phone? Move? Need a new password?
You can change your account information here!!! <br /> <br />

previous data

TESTING : <span> <?php echo $User_Info["First_Name"]; ?></span> <!-- LINE 129! ERROR FOUND HERE.-->
</div> <!-- end of registration info --> <!-- info for registration. -->

注意:我删除了不适用于此问题的额外代码。第 129 行已被注释以找到它。而且这两段代码都在同一页面上。我还应该提到,虽然我没有包含连接信息,但与数据库的连接也正常工作。

对于此事的任何帮助将不胜感激。

最佳答案

如果出现 SQL 错误,Mysqli_query 只会返回 false。替换结果中的 if:

// Use
if (mysqli_num_rows ( $UDD ) > o)

// Instead of
if($UDD)

您的查询似乎返回一个空集,因此 $UDD 设置为 true 而不是结果集。

关于php - 显示 MYSQL 结果时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20387153/

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