0

我对编码不太熟悉,因为我是这个世界的新手并且正在苦苦挣扎,所以请让我知道会话如何解决和工作。我的这段代码虽然没有给出任何错误,但显示的是空白页而不是结果。请帮忙!

<?
session_start();
include_once("config.php");

if($_SESSION['email']){
    header('location:home.php');
        }elseif(!isset($_SESSION['email'])){

if(isset($_POST['email']) && isset($_POST['pwd'])){

    }

$email=mysql_real_escape_string($_POST['email']);
$pwd=mysql_real_escape_string($_POST['pwd']);
$password=md5($pwd);


    $query="select * from users where email='".$email."'";// and password='".$password."'";
    $exec=mysql_query($query);
    $count=mysql_num_rows($exec);

//  echo $count; exit;

    if($count==1){
    while($result=(mysql_fetch_array($exec))){

        $fname=ucfirst($result[1]);
        $lname=ucfirst($result[2]);     
        $_SESSION['fname']=$result[1];  
        $_SESSION['lname']=$result[2];  
        echo "Welcome ". $_SESSION['fname']. " " .$_SESSION['lname'];

        }
    }elseif ($count > 1){

        }elseif ($count < 1){
            $error="Sorry! Your account is not registered.";
            header('Location: index.php?err="'.$error.'"');

            }
        }
?>
4

2 回答 2

1

当查询返回多个结果时,您什么也不做

elseif ($count > 1){
  echo "here";
}

尝试上面的代码并检查它是否有任何改变

于 2013-07-05T10:35:02.340 回答
0

试试这个,我希望它会工作,

if($_SESSION['email']){
    header('location:home.php');
        }
elseif(!isset($_SESSION['email'])){

      if(isset($_POST['email']) && isset($_POST['pwd'])){
                   $email=mysql_real_escape_string($_POST['email']);
                   $pwd=mysql_real_escape_string($_POST['pwd']);
                   $password=md5($pwd);
    $query="select * from users where email='".$email."'";// and password='".$password."'";
    $exec=mysql_query($query);
    $count=mysql_num_rows($exec);
    if($count==1){
    while($result=(mysql_fetch_array($exec))){

        $fname=ucfirst($result[1]);
        $lname=ucfirst($result[2]);     
        $_SESSION['fname']=$result[1];  
        $_SESSION['lname']=$result[2];  
        echo "Welcome ". $_SESSION['fname']. " " .$_SESSION['lname'];

        }
    }elseif ($count > 1){

           echo "Count > 1";

        }
     elseif ($count < 1){
            $error="Sorry! Your account is not registered.";
            header('Location: index.php?err="'.$error.'"');

            }
        }
}
else
{  echo "Empty fields";  }


?>
于 2013-07-05T11:06:02.357 回答