2015-09-05 83 views
0

當我執行下面的代碼,我得到這個錯誤:「mysql_num_rows預計參數1是資源」的錯誤查詢

Warning: mysql_num_rows() expects parameter 1 to be resource, object given in C:\wamp\www\my\myWork.php on line 53

請告訴我錯這個代碼?

<?php 
if(isset($_POST['login'])) 
{ 
    $servername = "localhost"; 
    $username = "root"; 
    $password = ""; 
    $dbname = "Begin"; 

    $uName = $_POST["txtUsername"]; 
    $uPwd = $_POST["txtPwd"]; 

    echo "Your Username is: ".$uName."<br>"; 
    echo "Your password is: ".$uPwd."<br>"; 

    $conn = mysqli_connect($servername, $username, $password, $dbname); 
    if(!$conn) 
     die("Connection faild: " . mysqli_connect_error()); 

    $sql = "SELECT firstname from myguests WHERE firstname = '$uName'"; 
    $result = $conn->query($sql); 

    if(mysql_num_rows($result) > 0) 
     { 
      echo "You have a login"; 
      $_SESSION['uname'] = $uName; 
     } 
    else 
     echo "You don't have a login"; 
} 
?> 

回答

2

我相信,因爲你使用的mysqli_connect,你需要使用mysqli_query($conn,$sql)符號。

試試這個:

$result = mysqli_query($conn,$sql) 
if(mysqli_num_rows($result) > 0) 
相關問題