我正在尝试将值从Login.php页面传递到Dashboard.php。但是,它没有显示任何输出。
的login.php
//there are no spaces before this
<?php
session_start();
$username= $_POST["txtUsername"]; //it does contain a value
if (empty($_POST["txtUsername"])) {
echo "<script> alert('Please enter username.')</script>";
$url = 'Homepage.php';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
else
{
$query= "Select User_ID, U_Username, U_Password from users where U_Username='$username' and U_Password='$pass'";
$result=mysql_query($query);
$count=mysql_num_rows($result);
$row=mysql_fetch_array($result);
if($count==1) //and count is 1
{
$_SESSION['login_user'] = $row['U_Username'];
$url = 'Dashboard.php';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
}
else
{
echo "<script> alert('Invalid Username or Password.')</script>";
$url = 'Homepage.html';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
}
}
?>
Dashboard.php
<?php
session_start();
echo $_SESSION['login_user'];
?>
//html code after this
当显示Dashboard.php时,它仅显示html代码的结果,并且不会回显会话变量。
请建议..
答案 0 :(得分:0)
请检查您的if条件和“$ row ['U_Username']”的值。我把$ count&amp;的价值$ row ['U_Username']硬编码并显示输出。