loginProcess.php :<?php //接受用户的数据
//1.id
$id=$_POST["id"];
//2.密码
$password=$_POST["password"];

//到数据库去验证 mysql扩展库 mysqli扩展库
//1.得到连接
$conn=mysql_connect("localhost","root","root"); if(!$conn){
die("链接失败".mysql_errno());
}
//设置访问数据库的编码
mysql_query("set names utf-8",$conn) or die(mysql_errno());
//选择数据库
mysql_select_db("empmanage",$conn) or die(mysql_errno());

//发送sql语句,验证
//防止sql注入攻击,变化验证逻辑
$sql="select password from admin where id=$id";

//通过输入的id来获取数据库的密码,然后在和输入的密码比对.
$res=mysql_query($sql,$conn); if($row = mysql_fetch_assoc($res)){
//查询到
//取出数据库密码
if(($row["password"]== md5($password))){
//说明合法
header("Location: empManage.php");

}

}
header("Location: login.php?errno=1");
exit(); mysql_free_result($res);
mysql_close($conn);


/*
//简单验证(不到数据库)
if($id=="100"&&$password=="123"){
//合法,跳转到empManage.php
header("Location:empManage.php");
//如果要跳转,则最好exit()
exit();
}else{
//非法用户
header("Location:login.php?errno=1");
exit();
}
*/
?>
代码如上,不连接数据库的话可以正常跳转到empManage.php   
连接数据库后出现空白页,跳转到的页面是loginProcess.php本身,怎么回事啊,在线等解答!!

解决方案 »

  1.   

    header()前不能有输出;
    必须置于页面HEAD的前面;
    根据楼主的问题,检查:
    数据库能否正常连接;
    编码是否一致;
    $row["password"] 和 md5($password) 是否有相等的值
      

  2.   

    我没看出代码有什么错误,建议你先调试看看。把header()改成echo(); 看看有没有输出什么。另外,看一下你是否有打开错误提示
      

  3.   

    $res=mysql_query($sql,$conn);
    这句没有判错
    可能导致 if($row = mysql_fetch_assoc($res)){ 有错,由于错误显示未打开,所以是空白页