...

View Full Version : FATAL ERROR Call to a member function query() on a non-object



2Pacalypse
08-10-2008, 08:47 PM
$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

zackwiny
08-10-2008, 09:13 PM
$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.

2Pacalypse
08-10-2008, 09:29 PM
It says that error is with line 68 - which is the line I posted.

GJay
08-10-2008, 09:39 PM
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.

jaap
08-11-2008, 08:31 AM
Where did you declare $db? I'm guessing: not.

2Pacalypse
08-11-2008, 02:09 PM
Ok I don't think I'm allowed to paste all this, but I'll edit it when I get it answered!


<?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');

?>

CFMaBiSmAd
08-11-2008, 02:33 PM
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.

2Pacalypse
08-11-2008, 02:37 PM
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?

GJay
08-11-2008, 05:31 PM
$db = new Something();

where Something is the name of a class that has (at least) a query() method.

2Pacalypse
08-11-2008, 06:52 PM
$db = new Something();

where Something is the name of a class that has (at least) a query() method.



lol

Wut? :confused:

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum