【发布时间】:2013-12-15 11:20:10
【问题描述】:
我正在学习 php。我创建了一个注册和登录系统。它工作正常。但我很好奇:如何在用户个人资料中显示用户详细信息。例如姓名、姓氏、电子邮件等。我的登录系统正常运行,但仅显示电子邮件。
这是我的 profile.php 代码。
<?php
session_start();
if (!isset($_SESSION['email'])) {
header('location: index2.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="css/profile.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">
<div class="header_in">
<div class="logo"><span>EcoWebTr</span></div>
<div class="cik"><a href="cikis.php">Çıkış</a></div>
<!--Login informtion--></div>
</div>
<div class="container">
<div class="wrapper">
User Email:
<font color="#000066"><?php echo $_SESSION['email']; ?></font>
</div>
</div>
</body>
</html>
这也是 login.php
<?php
include("includes/connect.php");
if(isset($_POST['login'])) {
$email = $_POST['email'];
$password = md5($_POST['password']);
$check_user = "SELECT * FROM users WHERE email='$email' AND password='$password'";
$run = mysql_query($check_user);
if(mysql_num_rows($run)>0) {
$_SESSION['email']=$email;
echo"<script>window.open('profile.php','_self')</script>";
} else {
echo"<script>alert('wrong email or password')</script>";
}
}
?>
【问题讨论】:
-
根据您提供的数据,不可能给您一个完整的答案。但通常人们会根据作为输入提供的键值从数据库中选择数据。
-
根据您编辑的问题/代码
session_start();也需要在login.php内,并阅读我在此评论上方给您的链接。您需要先为其分配一个变量。 “如何”在该链接中。 -
请不要再使用
mysql_*函数。它们已被弃用并且容易被注射。请参阅stackoverflow.com/questions/12859942/… 了解更多信息