2012-12-19 21 views
-3

可能重複:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select錯誤MYSQL預計Paramater爲1?

有人可以幫助我。我設置了一個div,只在帳戶類型爲「已付款」的用戶登錄時才顯示。

工作正常,當「付費」用戶登錄到div顯示時,除此之外,如果用戶註銷提出這個錯誤信息,我不知道爲什麼?

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/PTB1/includes/mod_profile/mod_star_rating/mod_rating.php on line 116 

CODE:

<?php 

$account_type = account_type(); 
while ($acctype = mysql_fetch_array($account_type)) 


if ($acctype['account_type'] == 'paid') { 
    if (logged_in()) { ?> 
    <div class="rate-button">can rate</div><? 


} 
?> 

這裏是我的帳戶類型功能:

function account_type() { 
      global $connection; 
      global $_SESSION; 
      $query = "SELECT account_type 
         FROM ptb_users 
         WHERE id = ".$_SESSION['user_id']." "; 
      $account_type = mysql_query($query, $connection); 
      confirm_query($query, $connection); 
      return $account_type; 
     } 
+0

SQL語句在哪裏? –

+0

account_type()是什麼?另外,停止使用mysql_ *函數。 –

+0

您可能想要提供account_type()的代碼 – datasage

回答

0

首先mysql_功能已被棄用,並應與庫MySQLi或PDO來代替。

$ account_type可能是錯誤的,會解釋您的錯誤。你會想添加一些檢查,以便得到mysql_error()的結果。

你會想要做這樣的事情:

if(!$account_type) { 
    die(mysql_error()); 
} 
1
$acctype = mysql_fetch_array($account_type); 

屬於跟在後面

$account_type = mysql_query($query, $connection); 

通過

return $acctype; 

和主腳本應該閱讀: $ acc_type = acco unt_type(); 而不是

while