dongshao5573 2012-12-13 15:45
浏览 42

这段代码中的错误是什么?它总是在其他地方

Why is this code not working?

It always go in else and set $_SESSION['wronglogin']=1; it is a login script which takes input of email-id and password and then checks that if any such thing exists then it should start $_SESSION['loggedin'] otherwise $_SESSION['wronglogin']. I have tried a lot but i am just not getting it

$_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');
}
  • 写回答

2条回答 默认 最新

  • dqu3974 2012-12-13 16:31
    关注

    can you copy the output of this,

    <?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');
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line