dprntkxh703029 2012-04-22 04:00
浏览 74
已采纳

PHP脚本不在IF语句中输入ELSE子句(登录测试)

I'm stumped on this one. Very simple login screen. When there is a password match the script works perfectly and jumps to main.php. When the uname or pswd is wrong, the script wont drop into the ELSE clause and wont go to badlogin.php. The script just hangs with the blank white screen.

any help would be great.

<?php
include("dbconnect.php");
$u_name = mysql_real_escape_string($_POST['uname']);
$p_word = mysql_real_escape_string($_POST['pword']);
# *** querying all records ***
$query = mysql_query("SELECT * FROM notes_users WHERE valid_password = '$p_word' && valid_username = '$u_name'");
while($rst = mysql_fetch_array($query)) {

if (($rst[valid_username] == $u_name) AND ($rst[valid_password] == $p_word)) {
    session_start();
    $_SESSION['login'] = "1";
    header('Location: main.php') ;
} else {
    session_start();
    $_SESSION['login'] = '';
    header('Location: badlogin.php') ;
}

}

?>
  • 写回答

3条回答 默认 最新

  • douping7105 2012-04-22 04:14
    关注

    If there's no results returned from the query then "while($rst = mysql_fetch_array($query))" will never prove true, and the while loop is skipped over entirely.

    edit: You could change it to a "do while" or just fix your while conditional.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)