这是显示输入数据的位置。目前,它只是显示电子邮件,它不会显示电话,城市和county.I想显示所有这些信息为用户在其中输入数据的特定用户如何从PHP中的不同页面检索会话信息?
<?php
session_start();
if(!($_SESSION['email'])){
header("location: login.php");
}
?>
<html>
<head>
<title>Login Page</title>
</head>
<style type='text/css'>
body{
background:url('wellcome.png');
}
</style>
<body><b>Welcome you have succesfully logged into your account</b>
<p></p>
<font color='red' size='5'><?php echo $_SESSION['email'];?>
</font>
<font color='red' size='5'><?php echo $_SESSION['name'];?>
<font color='red' size='5'><?php echo $_SESSION['phone'];?>
<font color='red' size='5'><?php echo $_SESSION['city'];?>
<font color='red' size='5'><?php echo $_SESSION['county'];?>
</font>
<h1 align='right' style='margin-right:50px; margin-top:50px'>
<a href='logout.php'>Logout Here</a></h1>
</body>
</html>
这就是:
<html>
<head>
<title>Registration Forma</title>
</head>
<body>
<form method='post' action='registration.php'>
<table width='400' border='5' align='center'>
<tr>
<td colspan = '5'><h1>Registration Form</h1></td>
</tr>
<tr>
<td align = 'center'>User Name:</td>
<td><input type='text' name='name'/></td>
</tr>
<td align = 'center'>Phone Number:</td>
<td><input type='text' name='phone'/></td>
</tr>
<td align = 'center'>County:</td>
<td><input type='text' name='county'/></td>
</tr>
<td align = 'center'>City/Town:</td>
<td><input type='text' name='city'/></td>
</tr>
<tr>
<td align = 'center'>User Paswword:</td>
<td><input type='password' name='pass'/></td>
</tr>
<tr>
<td align = 'center'>Email:</td>
<td><input type ='text' name='email' /></td>
</tr>
<tr>
<td colspan='5' align='center'><input type='submit' name='submit' value='sign up' /></td>
</tr>
</table>
</form>
<center><B>Already Registered </b> <a href='login.php'>Login here</a></center>
</center>
</body>
</html>
<?php
$servername = "localhost";
$username = "root"; $password = "";
$dbname = "users_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if (mysqli_connect_errno())
{ echo "MySQLi Connection was not established: " . mysqli_connect_error();
}
if(isset($_POST['submit']))
{ $user_name = $_POST['name'];
$user_pass = $_POST['pass'];
$user_email = $_POST['email'];
$Phone = $_POST['phone'];
$County = $_POST['county'];
$City = $_POST['city'];
if($user_name=='')
{ echo "<script>alert('Please enter your name!')</script>";
exit(); }
if($user_pass=='')
{ echo "<script>alert('Please enter your password!')</script>";
exit(); } if($user_email=='')
{ echo "<script>alert('Please enter your email!')</script>";
exit(); }
//CHECKING FIELDS
$check_username = "SELECT * FROM users WHERE user_name = '$user_name'";
$result_username= mysqli_query($conn, $check_username) or die (mysqli_error($conn));
if (mysqli_num_rows($result_username) > 0) {
echo "Username already exists, please try another one!";
exit();
}
$check_email = "SELECT * FROM users WHERE user_email = '$user_email'";
$result_email = mysqli_query($conn, $check_email) or die (mysqli_error($conn));
if (mysqli_num_rows($result_email) > 0)
{ echo "Email already exists, please try another one!";
exit(); }
//INSERTING DATA TO DATABASE
$insertquery = "INSERT INTO users (user_name,user_pass,user_email,Phone,County,City)
VALUES ('$user_name','$user_pass','$user_email','$Phone','$County','$City')";
if (mysqli_query($conn, $insertquery))
{ echo "<script>window.open('welcome.php','_self')</script>"; } else {
echo "Error: " . $insertquery . "<br>" . mysqli_error($conn);
}
}
?>
这是我的登录页面。这是用户输入他们的电子邮件和密码登录的地方。当用户登录进入欢迎页面时,我想让他们看到他们的个人信息,例如姓名,电话,城市和县。
<?php
session_start()
?>
<html>
<head>
<title>Login Page</title>
</head>
<style type='text/css'>
body{
background:url('back.jpg');
}
</style>
<body>
<form method='post' action='login.php'>
<table width='400' border='5' align='center'>
<tr>
<td colspan = '5'><h1>Login Form</h1></td>
</tr>
<tr>
<td align = 'center'>Paswword:</td>
<td><input type='password' name='pass'/></td>
</tr>
<tr>
<td align = 'center'>Email:</td>
<td><input type ='text' name='email' /></td>
</tr>
<tr>
<td colspan='5' align='center'><input type='submit' name='login' value='login' /></td>
</tr>
</table>
</form>
<center>
<font color='red' size='6'>registered yet?
</font><a href ='registration.php'>Sign up here</a>
</body>
</html>
<?php
$servername = "localhost";
$username = "root"; $password = "";
$dbname = "users_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if(isset($_POST['login'])){
$password = $_POST['pass'];
$email = $_POST['email'];
$check_email = "select * from users where user_pass='$password' AND user_email='$email'";
$run = mysqli_query($conn, $check_email) or die (mysqli_error($conn));
if (mysqli_num_rows($run) > 0)
{
$data = mysqli_fetch_array($check_email);
$_SESSION['email']=$data['user_email'];
$_SESSION['name']=$data['user_name'];
$_SESSION['phone']=$data['Phone'];
$_SESSION['county']=$data['County'];
$_SESSION['city']=$data['City'];
echo
"<script>window.open('welcome.php','_self')</script>";
}
else{
echo "<script>alert('Email or password is incorrect!')</script>";
}
}
?>
我没有看到你设置了会话的位置 – Mihai
**这是你的意思吗?这是从我的登录页面** if(isset($ _ POST ['login'])){ \t $ password = $ _POST ['pass']; \t $ email = $ _POST ['email']; \t \t \t $ check_email =“select * from user where user_pass ='$ password'AND user_email ='$ email'”; \t \t \t $ run = mysqli_query($ conn,$ check_email)or die(mysqli_error($ conn)); \t如果(mysqli_num_rows($运行)> 0) \t { \t \t $ _SESSION [ '电子邮件'] = $电子邮件; \t \t \t \t \t 回声\t \t \t “”; \t \t} \t其他{\t \t \t回声 “”; \t \t} \t } > – artur
电子邮件均田,你只设置会话这里'$ _SESSION [“电子邮件”] = $电子邮件;'做所有其他人一样 – Mihai