PDA

View Full Version : Call to a member function on a non-object...


TrainHealthy
10-25-2005, 08:04 AM
Hi,

At the bottom of my page i get this:

Fatal error: Call to a member function on a non-object in /home/content/l/a/w/lawjigga/html/forum/includes/functions.php on line 4308

Line 4308 is:
$vbulletin->db->unlock_tables();

I'm not a guru when it comes to PHP so I can't seem to see the problem.

Here's all the code on my page.

At very top of page:

//Userpanel.php
chdir("/home/content/l/a/w/lawjigga/html/forum");
require('./global.php');
include('./includes/functions_user.php');
chdir("/home/content/l/a/w/lawjigga/html/");


In body (fetches news):

$newsforums = 2;
$newsitems = 5;
$forumspath = "";

chdir("/home/content/l/a/w/lawjigga/html/forum");
$connection = mysql_connect(**************) or die ("Cannot connect to server.");
$db = mysql_select_db("trainhealthy", $connection) or die ("Could not select database.");
$sql = "SELECT threadid, title, forumid, replycount, postusername, postuserid, lastposter, dateline, iconid FROM thread WHERE forumid = \"$newsforums\" ORDER BY threadid DESC LIMIT $newsitems";
$sql_result = mysql_query($sql, $connection) or die ("Could not execute query.");

if (!$sql_result) {
echo "<p>Could not get record.";
}

while ($row = mysql_fetch_array($sql_result)) {
$threadid = $row["threadid"];
$title = $row["title"];
$forumid = $row["forumid"];
$replycount = $row["replycount"];
$postusername = $row["postusername"];
$postuserid = $row["postuserid"];
$lastposter = $row["lastposter"];
$iconid = $row["iconid"];
$dateline = $row["dateline"];

$sql2 = "SELECT postid, threadid, username, userid, title, dateline, pagetext, iconid FROM post WHERE threadid = \"$threadid\" ORDER BY postid ASC LIMIT 1";
$sql_result2 = mysql_query($sql2, $connection) or die ("Could not execute query in second sql statement.");

if (!$sql_result2) {
echo "<p>Could not get record in second statement.";
}

while ($row2 = mysql_fetch_array($sql_result2)) {
$pagetext = $row2["pagetext"];
$dateposted = date("D j M Y, g:i A",$dateline);

if ($replycount==1) {
$commenttext = "Comment";
}
else {
$commenttext = "Comments";
}

$bericht=$pagetext;


print "
<table border=\"0\" width=\"100%\" id=\"table1\" cellspacing=\"0\" cellpadding=\"2\">
<tr>
<td width=\"100%\">
<h2><b>$title</b></h2> - <img border=0 src=\"http://biorust.com/images/qbullets/edit.gif\"><a href=\"http://forums.trainhealthy.com/thread$threadid.html\"><b>$replycount</b> $commenttext</a><br>
:: Posted By <a href=\"http://forums.trainhealthy.com/member.php?s=&action=getinfo&userid=$postuserid\"><b>$postusername</b></a> at <i>$dateposted</i></a>
</tr>
<tr>
<td width=\"100%\">
<p align=\"justify\">".$bericht."</td>
</tr>
</table>
<p>
";

}
}

echo "<center><a href=\"http://forums.biorust.com/search.php\">Search the News</a> | <a href=\"http://forums.biorust.com/forum3.html\">View All News Posts</a></center>";

mysql_free_result($sql_result);
mysql_close($connection);

chdir("/home/content/l/a/w/lawjigga/html");


IN body (non vb login box):

if ($vbulletin->userinfo['userid'] != 0)
{
echo "You are logged in as <b>";
echo $vbulletin->userinfo['username'];
echo "</b>.<br /><br />";

//Lastvisit
$currentmonth = date("F");
$lastvisitedmonth = date("F", $vbulletin->userinfo['lastvisit']);
if($currentmonth == $lastvisitedmonth){

$userlastvisit = date("g:i a", $vbulletin->userinfo['lastvisit']);
$lastvisitday = date("j", $vbulletin->userinfo['lastvisit']);
$daytoday = date("j");

if($daytoday == $lastvisitday){
$timesuffix = "Today";
}
if(($daytoday -1) == $lastvisitday){
$timesuffix = "Yesterday";
}
echo "Last Visit: ".$userlastvisit." ".$timesuffix;
}
else {
$userlastvisit = date("g:i a, F j Y", $vbulletin->userinfo['lastvisit']);
echo "Last Visit: ".$userlastvisit;
}

//
echo "<br /><br />";
echo "<u>PM Stats</u><br />" ;
if($vbulletin->userinfo['pmunread'] != 0) {

echo "Unread: ";
if($vbulletin->userinfo['pmunread'] <= 1) {
echo $vbulletin->userinfo['pmunread'];
echo "<br />";
echo "Total:";
}
}
if($vbulletin->userinfo['pmunread'] != 1 AND $vbulletin->userinfo['pmunread'] <= 2 AND $vbulletin->userinfo['pmunread'] != 0) {

echo "Unread: ";
echo $vbulletin->userinfo['pmunread'];
echo "<br /><b>Total:</b>";

}

if($vbulletin->userinfo['pmunread'] == 0) {

echo "Unread: ";
echo $vbulletin->userinfo['pmunread'];
echo "<br />Total :";

}


echo $vbulletin->userinfo['pmtotal'];
echo "<br />";
echo "<br />";
echo "<a href=forum/login.php?$session[sessionurl]do=logout&amp;logouthash=$logouthash";
echo $vbulletin->userinfo['logouthash'];
echo ">";
echo " Log Out";
echo "</a>";

}

if ($vbulletin->userinfo['userid'] == 0)
{
echo "
<style type=text/css>
<form action=forum/login.php method=post onsubmit=md5hash(vb_login_password,vb_login_md5pas sword,vb_login_md5password_utf)>
<script type=text/javascript src=forum/clientscript/vbulletin_md5.js></script>
<table cellpadding=0 cellspacing=$stylevar[formspacer] border=0>
<tr>
<td >Username:<br />
<input class=\"textbox\" name=vb_login_username type=text id=navbar_username accesskey=u tabindex=1 onfocus=if (this.value == '$vbphrase[username]') this.value = ''; size=15 />
<br />
Password:<br />
<input class=\"textbox\" name=vb_login_password type=password accesskey=p tabindex=2 size=15 /><br />
<label for=cb_cookieuser_navbar><input name=cookieuser type=checkbox id=cb_cookieuser_navbar accesskey=c tabindex=3 value=1 checked=checked />Remember</label><br /><br />
<input class=\"submit\" type=submit accesskey=s tabindex=4 title=$vbphrase[enter_username_to_login_or_register] value='Log In' />
<br />
<a href=\"http://trainhealthy.com/forum/login.php?do=lostpw\">Lost Password?</a> ||
<a href=\"http://trainhealthy.com/forum/register.php\">Register</a></td>
</tr>
</table>
<input type=hidden name=s value=$session[sessionhash] />
<input type=hidden name=do value=login />
<input type=hidden name=vb_login_md5password />
<input type=hidden name=vb_login_md5password_utf />
</form>
<!-- / login form -->";
}


Anyhelp is appreciated!

Xenon
10-25-2005, 11:08 AM
i've removed the username and password of your db connection.
be careful not to post such informations when asking for help ;)

as for your question, normally that's because you are calling the db within a function without globalizing that object.

try to add a global $vbulletin; before the errorproducing line.


also try to use better formating of your code, codingstandarts help when it comes to find bugs :)

TrainHealthy
10-25-2005, 12:37 PM
i've removed the username and password of your db connection.

Thanks, I'll try to watch out next time :nervous:


try to add a global $vbulletin; before the errorproducing line.
Do you mean putting $vbulletin before line 4308 in funtions.php?

Xenon
10-25-2005, 01:28 PM
yep, exactl one line before there should be a
global $vbulletin;

TrainHealthy
10-25-2005, 03:03 PM
No change :(

Marco van Herwaarden
10-26-2005, 10:32 AM
The database you are accessing, is this also the database for your forum? If yes, try to use the standard vB functions for accessing the database.

$connection = mysql_connect(**************) or die ("Cannot connect to server.");
$db = mysql_select_db("trainhealthy", $connection) or die ("Could not select database.");
Here you are probably destroying the vB database connection, resulting in the error you are getting.