Call to a member function on a non-object :(

  • Jon

    Jon - 2005-11-20

    Why am i getting this message. I am coding an application called phpSIGS, but i keep getting this error: Fatal error: Call to a member function on a non-object in C:\Program Files\XAMPP\xampp\htdocs\development\index.php on line 20. Code is below:
    /* phpSIGS
    * Homepage

    require 'include/mysql/';
    require 'header.php';
    //require 'include/';
    //require 'include/jpgraph/jpgraph.php';

    $db = ADONewConnection('mysql');
        $db->debug = true;
        $db->Connect($db_host, $db_username, $db_password, $db_database);
    function calculate_bandwidth()
        //Declare total vairable
        $total = 0;
        //execute mysql query and find out total bandwidth
        $db  = $db->Execute("SELECT * FROM phpsigs_bandwidth"); 
        while (!$resultid->EOF())
            $row = $db->fields; 
            $add = $row["transfered"];
            $total = $total + $add; 
        //Make size human readable , i.e. no 100000000000000000000000000000000000000000000000000 bytes.(from PHP.NET).
        $filesizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
        $total = round($total/pow(1024, ($i = floor(log($total, 1024)))), 2) . $filesizename[$i]; 
        echo $total;

    function create_bandwidth_graph()
        //Coming soon
    echo '<b>Welcome to yoursitename!</b><br />';
    echo 'Yoursitename is an dynamic sig hosting service, where you can have whats currenty playing in winamp, your Whatpulse stats and more in your sig! All of this can be managed in an easy to use control panel. You also have 50KB of disc space for your own signiture image, so you can customize it as much as you want. This service has transfered an total of'. calculate_bandwidth() .'!<br />\n';
    echo '<br />\n';
    echo ' <a href="signup.php"><center><b>Sign up now!!</b></center></a>\n';

    Any ideas?

    • Mark Dickenson

      Mark Dickenson - 2005-11-20

      This line...

      $db = $db->Execute("SELECT * FROM phpsigs_bandwidth"); 

      Should be...

      $resultid = $db->Execute("SELECT * FROM phpsigs_bandwidth"); 

    • Kevin Bennett

      Kevin Bennett - 2006-02-19

      Actually, the problem is the $db variable is not made available inside the function.

      Add this to the top of the function:

      global $db;


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks