2012-06-23 57 views
0

我試圖讓我的查詢中的行數,但它不斷給我這個錯誤檢索行NUM中的mysqli

試圖讓行非對象的特性15

<?php require_once("./includes/Utilities.php") ;?> 
<?php require_once("./includes/db_connection.php");?> 
<?php 
    if(isset($_POST['submit'])){ 
     $username = trim($_POST['username']); 
     $password = trim($_POST['password']); 
     $conf_pass = trim($_POST['conf_password']); 
     $email = trim($_POST['email']); 
     require_once('./includes/CheckPassword.php'); 
     $check_pwd = new Db_CheckPassword($password); 
     $check_pwd =$check_pwd->check(); 
     require_once('./includes/CheckUsername.php'); 
     $sql = "SELECT * FROM accounts WHERE username = {$username}"; 
     $result = $conn->query($sql); 
     $numRows = $result->num_rows; 
    } 
?> 

這是專門線15

$numRows = $result->num_rows; 

爲什麼會返回一個錯誤?

+0

當您使用MySQLi時,您並未使用準備好的語句!這導致舊版數據庫驅動程序引入了相同類型的SQL注入漏洞! –

+0

mysqli存儲過程與執行查詢有什麼區別? – KyelJmD

+0

我沒有說存儲過程,我說** [準備語句](http://il.php.net/manual/en/mysqli.quickstart.prepared-statements.php)** –

回答

3

因爲用戶名未被引用。

試試這個:

$sql = "SELECT * FROM accounts WHERE username = '{$username}'"; 
0

你是不是檢查,如果您的查詢是成功的,因此$result實際上可能含有虛假。