Jump to content

Any help would be much welcomed


thebear19857

Recommended Posts

I am getting the following error and can not work out why.

 

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Login System v.2.0\admin\admin.php on line 26

Error displaying info

 

This is the code I am using

 

function displayUsers(){

  global $database;

  $q = "SELECT username,userlevel,email,timestamp,fname,sname,address,city,county,postcode"

      ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username";

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

  /* Error occurred, return given name by default */

  $num_rows = mysql_numrows($result);

  if(!$result || ($num_rows < 0)){

      echo "Error displaying info";

      return;

  }

  if($num_rows == 0){

      echo "Database table empty";

      return;

  }

  /* 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>Last Active</b></td><td><b>First Name</b></td></tr><td><b>Surname</b></td><td><b>Address</b></td><td><b>City</b></td><td><b>County</b></td><td><b>Post Code</b></td><td><b>Phone No</b></td>\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");

      $time  = mysql_result($result,$i,"timestamp");

      $fname  = mysql_result($result,$i,"fname");

      $sname  = mysql_result($result,$i,"sname");

      $address  = mysql_result($result,$i,"address");

      $city  = mysql_result($result,$i,"city");

      $county  = mysql_result($result,$i,"county");

      $postcode  = mysql_result($result,$i,"postcode");

      $phone  = mysql_result($result,$i,"phone");

 

 

 

 

      echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>td>fname</td></tr><td>sname</td><td>address</td><td>city</td><td>county</td><td>postcode</td><td>phone</td>\n";

  }

  echo "</table><br>\n";

}

 

The blue line seems to be the problem line that the error is saying.

 

I would appreciate any help.

 

 

Link to comment
https://forums.phpfreaks.com/topic/102950-any-help-would-be-much-welcomed/
Share on other sites

In your sql query, you forgot to put a space between the field names and the 'FROM' key word

 

Here is the corrected sql query. Notice the space at the end of the first line of the query.

<?php 
$q = "SELECT username,userlevel,email,timestamp,fname,sname,address,city,county,postcode " .
         "FROM " . TBL_USERS . " ORDER BY userlevel DESC,username";
?>

 

You could have figured this out on your own if you would have printed out the sql query when you got the error message. People often make mistakes when creating sql queries, so the first thing you should do when you are having an SQL trouble, is echo the query and inspect it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.