這是顯示輸入數據的位置。目前,它只是顯示電子郵件,它不會顯示電話,城市和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