查询问题? - PHP问题和查询失败

时间:2014-01-31 21:54:44

标签: php mysql sql login username

我认为我的查询在这里失败了 - 因此我无法让我的登录页面工作。任何协助我帮助我意识到自己出错的地方都会受到高度赞赏。

我的代码 -

<?php
session_start();
$failure = $success = "";

if ($_SERVER["REQUEST_METHOD"] == "POST")
    {mysql_connect(-All the correct info is in here-) or die(mysql_error()); 
        mysql_select_db("flavedb") or die(mysql_error()); 

        $uname = $_POST['uname'];
        $uname = mysql_real_escape_string($uname);
        $password = $_POST['password'];
        $password = mysql_real_escape_string($password);
        $password = md5($salt.md5($password));

        $qry = "SELECT * FROM flave_users WHERE Username='".$uname."' AND Password=='".$password."'";
        $result = mysql_query($qry);

        if($result) {
            if(mysql_num_rows($result) == 1){
                session_regenerate_id();
                $user = mysql_fetch_assoc($result);

                $_SESSION['SESS_USER_ID'] = $user('UserID');
                $_SESSION['SESS_USER_NAME'] = $user('Username');
                session_write_close();

                $success = "Successful - Logged in"; 
            }
            else {
                $failure = "Wrong Username or Password";
                $print1 = print($uname);
                $print2 = print($password);
            }
        }
        else {
            die("Query Failed");
        }
    }
?>

2 个答案:

答案 0 :(得分:0)

你尝试过只使用一个=而不是==吗?我很确定它在mysql中不存在

SELECT * FROM flave_users WHERE Username='".$uname."' AND Password=='".$password."'"

答案 1 :(得分:0)

在查询之前和之后回显,看看它是否打印到屏幕上以缩小代码失败的位置