Php登录页面代码问题。登录页面加载消息显示无效登录

时间:2016-11-24 17:19:59

标签: php mysql

每次登录页面加载消息显示invaild登录。它不会检查if条件是否直接转到else。我回应我的SQL查询,它完全正常工作。但我不明白我在哪里弄错了。能帮帮我吗。

我的代码,

<?php
    #$error = "";
        $servername = "localhost";
        $username = "";
        $password = "";
        $dbname = "lg_db";
        $tb_name = "lgin";

        mysql_connect("$servername", "$username", "$password")or die("Cannot connect");
        mysql_select_db("$dbname")or die("Cannot connect to Database");

        $username = $_POST['username'];
        $pass = $_POST['password'];
$username=stripslashes($username);
$pass=stripslashes($pass);
$username=mysql_real_escape_string($username);
$pass=mysql_real_escape_string($pass);

        $sql="SELECT * FROM $tb_name WHERE Name='$username' and Password='$pass'";

        $result=mysql_query($sql);

        $count1=mysql_num_rows($result);

        if($count1 >=1)
        {
            session_start();
           $_SESSION['simple_login'] = $username;
            header("Location: index_new.php");
            exit();

        }else{
                 $error="Invalid Login";
        }
?>

1 个答案:

答案 0 :(得分:1)

感谢您的支持和帮助!我的问题得到了解决。我在html文件中添加了if($_SERVER["REQUEST_METHOD"] == "POST")和之前的POST数据。