配置文件页面上登录用户的php回显用户名
****我目前有一个非常基本但有效的系统,允许人们注册,然后登录查看他们的个人资料。然而,我试图添加'欢迎'用户名',以个人资料页,但我没有它的运气 这是login.php文件配置文件页面上登录用户的php回显用户名,php,mysql,login,echo,Php,Mysql,Login,Echo,****我目前有一个非常基本但有效的系统,允许人们注册,然后登录查看他们的个人资料。然而,我试图添加'欢迎'用户名',以个人资料页,但我没有它的运气 这是login.php文件 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>1D Affection | Login</title> </hea
<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>
1D情感|登录
电子邮件
密码
这是validate_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>
<?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>
1D情感
欢迎
马上就来
我不知道这是否有什么不同,但是profile.php在一个单独的子文件夹中
我想补充一点,我只学了几个小时的php,所以如果这很简单或者任何答案对我来说都没有意义,请原谅我
提前感谢。您的php中有这一行
$_SESSION['uname'] = $uname;
但是$uname没有在任何地方定义。u没有将任何值设置为
$uname
那么如何设置$\u会话['uname']=$uname代码>首先,您已经在页面上有sesion_start,因此如果以后有sesion_start,php可能会抛出错误(只是让您知道:)。此外,我认为用户名存储在数据库中?因此,如果我在my profile.php文件中添加“Welcome to my profile.php,它是否有效?您没有为$uname
分配任何值,那么您如何回显该值?@RJCreatives如果您为uname分配了有效值,是的,您将以这种方式打印出来。首先需要在某个时候将其存储在数据库中,然后在进行身份验证后,需要从数据库中检索。