用户名和密码不起作用

时间:2012-04-12 05:55:51

标签: php javascript mysql ajax jquery

伙计们,请检查我的代码..在http://localhost/mycart/login.php?is_ajax=1&username=srini&password=srini执行以下代码后,即使传递了有效的用户名和密码,也会收到此错误。请帮助我谢谢

  

mysql_num_rows()期望参数1为资源,布尔值为   第25行的C:\ wamp \ www \ mycart \ login.php,用户名'srini'和密码'srini'未找到

<?php

$is_ajax = $_REQUEST['is_ajax'];
if (isset($is_ajax) && $is_ajax) {
       error_reporting(E_ALL ^ E_NOTICE);
    $uname = $_REQUEST['username'];
    $pword = $_REQUEST['password'];

    $uname = htmlspecialchars($uname);
    $pword = htmlspecialchars($pword);

    echo $uname;
    echo $pword;

     $con = mysql_connect("localhost", "root", "root");

    if (!$con) {

        die('Connection Failed' . mysql_error());
    }

    mysql_select_db("test", $con);

   $result = mysql_query("SELECT * FROM login WHERE L1 = $uname AND L2 = $pword");
   $num_rows = mysql_num_rows($result);
    if ($num_rows > 0)
        echo "success";
    else
        echo "username '{$uname}' and password '{$pword}' not found";


mysql_close($con);

}
?>

2 个答案:

答案 0 :(得分:2)

您的结果可能是false。试试这个:

$result = mysql_query("SELECT * FROM login WHERE L1 = '".$uname."' AND L2 = '".$pword."'");

答案 1 :(得分:0)

在SQL查询中使用'来屏蔽字符串值:

$result = mysql_query("SELECT * FROM login WHERE L1 = '" . $uname . "' AND L2 = '" . $pword . "'");