-3

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

Can someone help me. I'm setting a div to show only when users with account type 'paid' is logged in.

It works fine, when 'paid' users are logged in the div shows, but otherwise if the user's are logged out it comes up with this error message and i don't know why?

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


 } 
 ?>

Here is my account type function:

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;
        }
Community
  • 1
  • 1

2 Answers2

1
$acctype = mysql_fetch_array($account_type);

belongs after

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

followed by

return $acctype;

and the main script should read: $acc_type = account_type(); instead of the

while
Adder
  • 5,613
  • 1
  • 22
  • 51
0

To start with mysql_ functions are deprecated and should be replaced with mysqli or PDO.

$account_type may be false with would explain your error. You will want to add some checking so you can get the result of mysql_error().

You will want to do something like this:

if(!$account_type) {
  die(mysql_error());
}
datasage
  • 18,795
  • 2
  • 46
  • 53