Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    96
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question FATAL ERROR Call to a member function query() on a non-object

    PHP Code:
    $q=$db->query("SELECT * FROM users WHERE laston>(unix_timestamp()-15*60) AND user_level>1 ORDER BY laston ASC"); 
    What is wrong with this? 0.0

    It used to work perfect, I added a new page to my site, but now it doesn't work, however others have said it works for them!

    Please help!

    Thanks

  • #2
    New Coder
    Join Date
    Aug 2008
    Posts
    17
    Thanks
    4
    Thanked 1 Time in 1 Post
    Quote Originally Posted by 2Pacalypse View Post
    PHP Code:
    $q=$db->query("SELECT * FROM users WHERE laston>(unix_timestamp()-15*60) AND user_level>1 ORDER BY laston ASC"); 
    What is wrong with this? 0.0

    It used to work perfect, I added a new page to my site, but now it doesn't work, however others have said it works for them!

    Please help!

    Thanks
    For anyone to help you probably need to post the rest of your code,
    because it's probably a problem with the code above it.

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    96
    Thanks
    4
    Thanked 0 Times in 0 Posts
    It says that error is with line 68 - which is the line I posted.

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    it's saying that $db isn't an object, so you obviously have an error (as in a mistake, not a PHP error) somewhere else. Post. More. Code.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #5
    New Coder
    Join Date
    Aug 2005
    Location
    Groningen, Netherlands
    Posts
    57
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Where did you declare $db? I'm guessing: not.

  • #6
    New Coder
    Join Date
    Jul 2008
    Posts
    96
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Ok I don't think I'm allowed to paste all this, but I'll edit it when I get it answered!

    PHP Code:
    <?php
    global $db,$c,$ir$set;
    $hc=$set['hospital_count'];
    $jc=$set['jail_count'];
    $ec=$ir['new_events'];
    $mc=$ir['new_mail'];
    if(
    $ir['hospital'])
    {
      print 
    "<a href='hospital.php'>Hospital ($hc)</a><br />
      <a href='inventory.php'>Inventory</a><br />"
    ;
    }
    elseif(
    $ir['jail'])
    {
      print 
    "<a href='jail.php'>Jail ($jc)</a><br />";
    }
    else
    {
      print 
    "<a href='index.php'>Home</a><br />
      <a href='inventory.php'>Inventory</a><br />"
    ;
    }
    if(
    $ec 0) { print "<a href='events.php' style='font-weight: 800;'>Events ($ec)</a><br />"; }
    else { print 
    "<a href='events.php'>Events (0)</a><br />"; }
    if(
    $mc 0) { print "<a href='mailbox.php' style='font-weight: 800;'>Mailbox ($mc)</a><br />"; }
    else { print 
    "<a href='mailbox.php'>Mailbox (0)</a><br />"; }
    if(
    $ir['jail'] and !$ir['hospital'])
    {
      print 
    "<a href='gym.php'>Jail Gym</a><br />
      <a href='hospital.php'>Hospital ($hc)</a><br />"
    ;
    }
    else if (!
    $ir['hospital'])
    {
      print 
    "<a href='explore.php'>Explore</a><br />
      <a href='gym.php'>Gym</a><br />
      <a href='criminal.php'>Crimes</a><br />
      <a href='job.php'>Your Job</a><br />
      <a href='education.php'>Local School</a><br />
      <a href='hospital.php'>Hospital ($hc)</a><br />
      <a href='jail.php'>Jail ($jc)</a><br />"
    ;
    }
    else
    {
      print 
    "<a href='jail.php'>Jail ($jc)</a><br />";
    }
    print 
    "<a href='forums.php'>Forums</a><br />";
    if(
    $ir['new_announcements'])
    {
    print 
    "<a href='ann.php' style='font-weight: 800;'>Announcements ({$ir['new_announcements']})</a><br />";
    }
    else
    {
    print 
    "<a href='ann.php'>Announcements (0)</a><br />";
    }
    print 
    "
    <a href='newspaper.php'>Newspaper</a><br />
    <a href='search.php'>Search</a><br />"
    ;
    if(!
    $ir['jail'] && $ir['gang'])
    {
      print 
    "<a href='yourgang.php'>Your Gang</a><br />";
    }
    if(
    $ir['user_level'] > 1)
    {
    print 
    "<hr />
    <a href='staff.php'>Staff Panel</a><br />\n"
    ;



    print 
    "<hr /><b>Staff Online:</b><br />";
    $q=$db->query("SELECT * FROM users WHERE laston>(unix_timestamp()-15*60) AND user_level>1 ORDER BY userid ASC");
    while(
    $r=$db->fetch_row($q))
    {
    $la=time()-$r['laston'];
    $unit="secs";
    if(
    $la >= 60)
    {
    $la=(int) ($la/60);
    $unit="mins";
    }
    if(
    $la >= 60)
    {
    $la=(int) ($la/60);
    $unit="hours";
    if(
    $la >= 24)
    {
    $la=(int) ($la/24);
    $unit="days";
    }
    }
    print 
    "<a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> ($la $unit)<br />";
    }
    }
    if(
    $ir['donatordays'])
    {
    print 
    "<hr />
    <b>Donator Features</b><br />
    <a href='friendslist.php'>Friends List</a><br />
    <a href='blacklist.php'>Black List</a>"
    ;
    }
    print 
    "<hr />
    <a href='preferences.php'>Preferences</a><br />
    <a href='preport.php'>Player Report</a><br />
    <a href='helptutorial.php'>Help Tutorial</a><br />
    <a href='gamerules.php'>Game Rules</a><br />
    <a href='viewuser.php?u={$ir['userid']}'>My Profile</a><br />
    <a href='logout.php'>Logout</a><br /><br />
    Time is now<br />
    "
    ;
    echo 
    date ('F j, Y')."<br />".date('g:i:s a');

    ?>

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,108
    Thanks
    2
    Thanked 326 Times in 318 Posts
    The posted code is not creating an instance of the database class. The global keyword (your line of code immediately after the <?php tag) has no meaning outside of a function.

    Any page that uses your database class must create an instance of that class.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #8
    New Coder
    Join Date
    Jul 2008
    Posts
    96
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    The posted code is not creating an instance of the database class. The global keyword (your line of code immediately after the <?php tag) has no meaning outside of a function.

    Any page that uses your database class must create an instance of that class.
    What should it be then?

  • #9
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    PHP Code:
    $db = new Something(); 
    where Something is the name of a class that has (at least) a query() method.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #10
    New Coder
    Join Date
    Jul 2008
    Posts
    96
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by GJay View Post
    PHP Code:
    $db = new Something(); 
    where Something is the name of a class that has (at least) a query() method.


    lol

    Wut?

    I'm afraid that doesn't mean anything to me lol

    Any hints on excatly what needs to go in?

    Because it worked like a charm a few days ago 0.0


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •