0

伙计们,请检查我的代码..我通过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);

}
?>
4

2 回答 2

2

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

$result = mysql_query("SELECT * FROM login WHERE L1 = '".$uname."' AND L2 = '".$pword."'");
于 2012-04-12T05:58:52.163 回答
0

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

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

于 2012-04-12T05:59:19.607 回答