显示MYSQL结果时出现问题


Trouble displaying MYSQL Results

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

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行已被注释以找到它。此外,这两段代码都在同一页上。我还应该提到,虽然我没有包括我的连接信息,但与数据库的连接也在工作。

在这件事上如有任何帮助,我们将不胜感激。

Mysqli_query只有在存在SQL错误的情况下才会返回false。替换结果上的if:

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

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