在尝试使用会话电子邮件成功登录并显示在页面后,我正在尝试启动会话。但是我在某个地方犯了一个错误。
这是我在登录页面上的代码
if($role == 0){
$sql = "SELECT id FROM customers WHERE email = '$email' and password =
'$password'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
if($count == 1 ) {
$_SESSION['Email2'] = $_POST['Email'];
header("Location:SystemHome.php");
}else {
echo " Your Login Name or Password is invalid";
}
然后在下一页代码
<?php session_start(); ?>
<?php
echo "Hello".$_SESSION['Email2']."";
?>
答案 0 :(得分:0)
您应该在第一页中添加session_start:
session_start(); // start the session
if($role == 0){
$sql = "SELECT id FROM customers WHERE email = '$email' and password =
'$password'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
if($count == 1 ) {
$_SESSION['Email2'] = $_POST['Email'];
header("Location:SystemHome.php");
}else {
echo " Your Login Name or Password is invalid";
}