Page 1 of 1

Error message help for a real newbie?

Posted: Sat May 27, 2006 1:50 pm
by StevenB
I have just recently left the NT server/access/.asp world and trying to learn Linux/mysql/myphpadmin/.php

My first task is to find a login script and this one looks great. The problem is that being new to all of it I'm not sure if its the code, connection or db structure that I'm choking on.

If you click on this page, you'll get these errors:

Code: Select all

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/www/stevenburt.com/include/database.php on line 199

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/www/stevenburt.com/include/database.php on line 210

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/www/stevenburt.com/include/database.php:199) in /home/www/stevenburt.com/include/session.php on line 46

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/www/stevenburt.com/include/database.php on line 210

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/www/stevenburt.com/include/database.php on line 199

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/www/stevenburt.com/include/database.php on line 210

If I google the error message I just come up with a lot of pages with the same error. I am hoping a trained eye could point me in the right direction or maybe suggest a resource link I can use to define errors while I am learning.

I can post the code if needed. Just tried to keep it short.

Thanks in advance for any help!

Steve

Posted: Sat May 27, 2006 1:58 pm
by twigletmac
There's an error with the connection to the database or the SQL queries - would be useful to see a bit of the code around where the errors are happening so we can help you debug a bit.

Mac

Posted: Sat May 27, 2006 1:58 pm
by Oren
I believe that the errors are pretty much informative. If you really want to learn PHP rather than just doing copy-paste work, you should start reading a good PHP book first, and then code your own (simple) scripts - this script is huge, especially for a noob.

Posted: Sat May 27, 2006 2:18 pm
by StevenB
Sure,

line 191-210

Code: Select all

/**
    * calcNumActiveUsers - Finds out how many active users
    * are viewing site and sets class variable accordingly.
    */
   function calcNumActiveUsers(){
      /* Calculate number of users at site */
      $q = "SELECT * FROM ".TBL_ACTIVE_USERS;
      $result = mysql_query($q, $this->connection);
      $this->num_active_users = mysql_numrows($result);
   }
   
   /**
    * calcNumActiveGuests - Finds out how many active guests
    * are viewing site and sets class variable accordingly.
    */
   function calcNumActiveGuests(){
      /* Calculate number of guests at site */
      $q = "SELECT * FROM ".TBL_ACTIVE_GUESTS;
      $result = mysql_query($q, $this->connection);
      $this->num_active_guests = mysql_numrows($result);
   }
Oren... Books are ordered, couldn't wait to get started, and I always learn best through application. This one seems to offer many learning possibilities. Didn't mean to offend.

Thanks for any and all input.

Posted: Sat May 27, 2006 3:04 pm
by twigletmac
Try adding a bit of error handling to the mysql_query() call, so:

Code: Select all

$result = mysql_query($q, $this->connection) or die(mysql_error().'<p>'.$q.'</p>');
instead of just

Code: Select all

$result = mysql_query($q, $this->connection);
That will give you MySQL's view on what's going wrong :)

Mac

Posted: Sat May 27, 2006 7:44 pm
by StevenB
Thanks twigletmac,

That was exactly what I needed! As I said before being new to all of it I couldn't tell where my problem was. Your line of code suggested that the table didn't exist and I knew I had done something wrong in the phpmyadmin. I reworked it and WAALA, works beutifuly now.

Thanks for all your help,

Steve