Hi, I am having trouble with my php or sql statement. Here's what is happening.

I have a login system that worked perfectly on my test server but once I moved it to the LIVE server I now get an error when I try to get a list of all the people signed up at the login system.

I know that the server connect is working fine because I can log in, I can create accounts, I can view my account and I can edit it but when I go to the admin.php it is supposed to list all the people in the database but instead I get this error:

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/.jazzmen/encom/encomwireless.com/user/admin/admin.php on line 26
Error displaying info

Here is the code found around the 'list' statement (i bolded line 26)

/**
 * displayUsers - Displays the users database table in
 * a nicely formatted html table.
 */
function displayUsers(){
   global $database;
   $q = "SELECT username,userlevel,email,firstname,lastname,company,address,city,prov,pcode "
       ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";
   $result = $database->query($q);
   /* Error occurred, return given name by default */
[B]   $num_rows = mysql_numrows($result);[/B]
   if(!$result || ($num_rows < 0)){
      echo "Error displaying info";
      return;
   }
   if($num_rows == 0){
      echo "Database table empty";
      return;
   }

Here is the table build:

/* Display table contents */
   echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n";
   echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>First Name</b></td><td><b>Last Name</b></td><td><b>Company</b></td><td><b>Address</b></td><td><b>City</b></td><td><b>Province</b></td><td><b>Postal Code</b></td></tr>\n";
   for($i=0; $i<$num_rows; $i++){
      $uname  = mysql_result($result,$i,"username");
      $ulevel = mysql_result($result,$i,"userlevel");
      $email  = mysql_result($result,$i,"email");
      $firstname = mysql_result($result,$i,"firstname");
      $lastname = mysql_result($result,$i,"lastname");
      $company = mysql_result($result,$i,"company");
      $address = mysql_result($result,$i,"address");
      $city = mysql_result($result,$i,"city");
      $prov = mysql_result($result,$i,"prov");
      $pcode = mysql_result($result,$i,"pcode");

  echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$firstname</td><td>$lastname</td><td>$company</td><td>$address</td><td>$city</td><td>$prov</td><td>$pcode</td></tr>\n";
   }
   echo "</table><br>\n";
}

Can anyone see what could be wrong or does anyone have any idea why this would work at one host and not another?

Any help you can offer is greatly appreciated! I've been driving myself crazy for a couple of days now looking for an answer 🙂

Thanks
Ayla

    The error means that this statement...

       $result = $database->query($q);
    

    ...is not returning a MySQL resource ID. Therefore either your query was rejected by MySQL for some reason, or there's a logic error in the class from which $database was instantiated. You could add some debugging by doing the following:

       $result = $database->query($q);
    if(!$result)
    {
       die("Query failed: $q - " . mysql_error());
    }
    

      This website and you users are amazing!
      That was exactly what i needed... turned out i had an error in my mysql table build! (typo)

      Thank you so vary very much!
      Ayla

        You're welcome.

        And now you've learned Murphy's law of programming number 1: If you do not validate the return value of a function, then it's probability of failing is increased by a factor of ten. 🙂

          Write a Reply...