【问题标题】:Pass value from PHP page从 PHP 页面传递值
【发布时间】:2015-08-21 07:52:31
【问题描述】:

我正在尝试将值从 Login.php 页面传递到 Dashboard.php。但是,它没有显示任何输出。

登录.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.'">'; 

    }

}   
}
   ?>

仪表板.php

    <?php
    session_start();
    echo $_SESSION['login_user'];

    ?>
    //html code after this

当 Dashboard.php 显示时,它只显示 html 代码的结果,不回显会话变量。

请多指教..

【问题讨论】:

  • 目前不在家,所以我无法测试您的代码...但是在加载仪表板后尝试查看页面的源代码?根据您的模板(html 代码),login_user 的回显可能只是不可见(但存在于代码中)?
  • 你能告诉你从哪里得到$row['U_Username'],它有没有价值,请检查。
  • 另外,session_start() 在两个脚本中都成功了吗?你可以检查它的返回值。请注意,如果您在此之前有输出,例如第一个脚本中的空格,它将失败。但这当然可能是复制粘贴错误。
  • Pbm 在您的变量 $count / 或 $row['U_Username'] 上。我将 $count 替换为 1,将 $row 替换为“balabblal”,它显示给我的是“blalblalbla”
  • @Mumchii 请检查我的回答。谢谢。

标签: php html session


【解决方案1】:

请检查您的 if 条件和“$row['U_Username']”的值。我把 $count & $row['U_Username'] 的值硬编码并显示输出。

【讨论】:

  • 尝试硬编码值,正如@anantkumarsingh 所提到的,仍然没有显示任何输出:S
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-01
  • 2012-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多