1

为什么这段代码不起作用?

它总是进入 else 并设置 $_SESSION['wronglogin']=1; 它是一个登录脚本,它接受电子邮件 ID 和密码的输入,然后检查是否存在任何此类内容,那么它应该启动 $_SESSION['loggedin'],否则启动 $_SESSION['wronglogin']。我已经尝试了很多,但我就是不明白

$_SESSION['login-id']=$loginid;
$_SESSION['loginpassword']=$loginpassword;


$loginid = stripslashes($loginid);
$loginpassword = stripslashes($loginpassword);
$loginid = mysql_real_escape_string($loginid);
$loginpassword = mysql_real_escape_string($loginpassword);

$con = mysql_connect("localhost", "moodabsz_naman", "database") or die(mysql_error());
mysql_select_db("moodabsz_database",$con) or die(mysql_error());

$sql="SELECT * 
FROM  user 
WHERE  `email_id` =  '$loginid'
AND  `password` =  '$loginpassword'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
if($count==1){
    $_SESSION['loggedin']=1;


    mysql_close($con);

    header('location: index.php');

}
else {

    $_SESSION['wronglogin']=1;
    echo "Wrong Username or Password";

    mysql_close($con);

    header('Location: index.php');
}
4

2 回答 2

0

上面的代码不起作用,因为缺少应该放在 PHP 代码第一行的session_start()函数。

<?php
session_start();
/*

The rest of your code

*/
?>
于 2012-12-13T17:14:35.707 回答
0

你能复制这个的输出吗?

<?php
$_SESSION['login-id']=$loginid;
$_SESSION['loginpassword']=$loginpassword;


$loginid = stripslashes($loginid);
$loginpassword = stripslashes($loginpassword);
$loginid = mysql_real_escape_string($loginid);
$loginpassword = mysql_real_escape_string($loginpassword);

$con = mysql_connect("localhost", "moodabsz_naman", "database") or die(mysql_error());
mysql_select_db("moodabsz_database",$con) or die(mysql_error());

$sql="SELECT * 
FROM  `user` 
WHERE  `email_id` =  '$loginid'
AND  `password` =  '$loginpassword'";

$result=mysql_query($sql) or die(mysql_error());

$count=mysql_num_rows($result);

echo 'Debug::Count-'.$count;

if($count==1){
    $_SESSION['loggedin']=1;


    mysql_close($con);

   // header('location: index.php');

}
else {

    $_SESSION['wronglogin']=1;
    echo "Wrong Username or Password";

    mysql_close($con);

    //header('Location: index.php');
}
于 2012-12-13T16:31:42.323 回答