du16178 2015-06-06 11:20
浏览 58

从PHP页面传递值

I am trying to pass value from Login.php page to Dashboard.php. However,it is not displaying any output.

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

When Dashboard.php is displayed it shows the result of the html code only and does not echo the session variable.

Kindly advise..

  • 写回答

1条回答 默认 最新

  • duanqin7791 2015-06-06 11:43
    关注

    kindly check your if condition and the value of "$row['U_Username']". i put the value of $count & $row['U_Username'] hard coded and it show the output.

    评论

报告相同问题?

悬赏问题

  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教