2012-04-12 65 views
0

夥計們,請檢查我的代碼..正在執行http://localhost/mycart/login.php?is_ajax=1&username=srini&password=srini執行下面的代碼然後即使通過有效的用戶名和密碼也會得到此錯誤。好心幫我感謝用戶名和密碼不能正常工作

mysql_num_rows()預計參數1是資源,布爾在 C中給出:上線25和用戶名 '作者Srini' 和密碼 '作者Srini' \ WAMP \ WWW \ mycart \ login.php中不發現

<?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

你的結果可能是false。試試這個:

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

謝謝主席先生..它的工作 – user1160126 2012-04-12 06:05:40

+0

接受的答案是說有道「謝謝你」 ;-) – 2012-04-12 06:11:46

0

使用'在您的SQL查詢來掩蓋字符串值:

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

+0

消毒您的輸入 – 2012-04-12 06:01:30