无法显示MYSQL结果

时间:2013-12-04 22:10:31

标签: php html mysql sql

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

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行进行了评论以找到它。这两段代码也在同一页面上。我还要提一下,虽然我没有包含我的连接信息,但与数据库的连接也正常。

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

1 个答案:

答案 0 :(得分:0)

如果存在SQL错误,则mysqli_query将仅返回false。替换结果上的if:

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

// Instead of 
if($UDD)

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