2016-05-21 268 views
-2

這是錯誤:警告:mysql_num_rows()預計參數1是資源,在布爾C中給出: XAMPP htdocs中卡丁車 login.php中第13行

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\carting\login.php on line 13

的代碼,其中所述錯誤發生:

$numrows = mysql_num_rows($result); 

這裏是我的全碼:

<?php 
session_start(); 
include("databases/connection.php"); 

if (isset($_POST['username']) && isset($_POST['password'])) { 

    $q = sprintf("SELECT * FROM admins WHERE username = '%s' AND password = '%s'", 
     mysql_real_escape_string($_POST['username']), 
     mysql_real_escape_string(md5($_POST['password'])) 
    ); 

    $result = mysql_query($q); 
    $numrows = mysql_num_rows($result); 
    if ($numrows > 0) { 
     $_SESSION['id'] = mysql_result($result, 0, "id"); 
     $_SESSION['name'] = mysql_result($result, 0, "name"); 
     $_SESSION['usertype'] = mysql_result($result, 0, "userlevel"); 

     echo '<script>alert("Congratulations you successfully logged in");window.location="/mikez/carting/index.php";</script>'; 
    } else { 

     echo '<div class="alert alert-info"> 
     <a href="/mikez/carting/index.php" class="close" data-dismiss="alert" aria-label="close">&times;</a>Invalid username and password 
     </div>'; 
    } 
} 
?> 

謝謝指教!^_^

+0

什麼'connection.php'的內容? –

+0

你的代碼看起來像是正確的,但你可以調試例如$ result = mysql_query($ q)或die(mysql_error());如果你的查詢有錯誤,那麼你可以知道那裏有什麼問題。 –

回答

0

大概在include("databases/connection.php");你的MySQL憑據不工作,檢查它們是否仍然有效(的phpmyadmin或任何你有可用的)

相關問題