php-echo配置文件页面上登录用户的用户名


php echo username of logged in user on profile page

****我目前有一个非常基本但有效的系统,允许人们注册,然后登录查看他们的个人资料。然而,我试图将"欢迎"用户名添加到个人资料页面,但我没有运气。

这是login.php 文件

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>1D Affection | Login</title>
</head>
<body>
    <form method="post" action="validate_login.php" >
        <table border="1" >
            <tr>
                <td><label for="email">Email</label></td>
                <td><input type="text" 
                  name="email" id="email"></td>
            </tr>
            <tr>
                <td><label for="pass">Password</label></td>
                <td><input name="pass" 
                  type="password" id="pass"></input></td>
            </tr>
            <tr>
                <td><input type="submit" value="Submit"/>
                <td><input type="reset" value="Reset"/>
            </tr>
        </table>
    </form>
</body>
</html>

这是validate_login.php

<?php
session_start();
// Grab User submitted information
$email = $_POST["email"];
$pass = $_POST["pass"];
// Connect to the database
$con = mysql_connect("mysql.onedirectionaffection.co.uk","robjef2","********");
// Make sure we connected succesfully
if(! $con)
{
    die('Connection Failed'.mysql_error());
}
// Select the database to use
mysql_select_db("onedirectionaffection_members",$con);
$result = mysql_query("SELECT email, pass FROM users WHERE email = $email");
$row = mysql_fetch_array($result);
if($row["email"]==$email && $row["pass"]==$pass)
  header("Location: ../../profile/profile.php");
else
    echo"Sorry, your credentials are not valid, Please try again.";
  session_start();
$_SESSION['uname'] = $uname;
?>

这是配置文件页面的当前代码-

<html>
  <head>
    <title>1D Affection</title>
    <link rel="stylesheet" Type="text/css" href="../css/stylesheet.css" />
    <link rel="stylesheet" Type="text/css" href="../css/font.css" />
    <link rel="stylesheet" Type="text/css" href="../css/profile.css" />
  </head>
  <body bgcolor="white">
    <div id="wrapperhead">
      <div id="headcont">
        <div class="logo">
          <img src="../images/1DA logo ripped.png" height="150px">
        </div>
        <div class="subheading">
          <img src="../images/1d subheading.png" height="150px">
        </div>
      </div>

      </div> <!--END OF HEADER-->
    <div id="nav">


      <div class="navigation">
        <ul>
          <li><a class="nav" href="../index.html">Home</a></li>
          <li><a class="nav" href="#">News</a></li>
          <li><a class="nav" href="#">Fan-fiction</a></li>
          <li><a class="nav" href="#">Gallery</a></li>
          <li><a class="nav" href="#">Testimonials</a></li>
          <li><a class="nav" href="http://www.onedirectionstore.com/" target="_blank">Store</a></li>
        </ul>
      </div> <!-- END OF MENU-->
         <!-- END OF NAVIGATION-->
    </div>
      <div id="wrappercontent">
        <div class="content">
          <div class="maincont">
            <div class="profcust">

          <div class="profpic">
            </div>
            <div class="profinfo">
            </div>
            </div>
        <div class="username">
         Welcome 
            </div>
        <div class="story">
            </div>

          </div>
      <div class="sidenav">
        Coming Soon
          </div>

        </div><!--end of content-->
    </div>

  </body>
</html>

我不知道这是否有什么不同,但profile.php在一个单独的子文件夹中。

我想补充一点,我只学习了php几个小时,所以如果这很简单,或者任何答案对我来说都没有意义,请原谅我。

提前谢谢。

php 中有这一行

$_SESSION['uname'] = $uname;

但$uname在任何地方都没有定义。