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

时间:2013-11-30 15:22:09

标签: php mysql login echo username

** * *我目前有一个非常基本但有效的系统,可让人们注册然后登录查看他们的个人资料。但是,我尝试将“欢迎”用户名“'添加到个人资料页面,但我没有运气。

这是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,所以请原谅我,如果这很简单,或者任何答案对我来说都没有意义。

提前致谢。

1 个答案:

答案 0 :(得分:1)

你的php中有这一行

$_SESSION['uname'] = $uname;

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