DeathStar Posted March 21, 2007 Share Posted March 21, 2007 Hi there, for the living hell out of me I can not get this error fixed! Code seems to be good! Here is the error i am getting: Fatal error: Call to a member function on a non-object in /hsphere/local/home/****/****/mailbox.php on line 185 Here is the lines 178 to 188: if ($r['display_pic']){ print "<img src='{$r['display_pic']}' hight='50' width='50'>";} else { print "<img src='nopic.jpg' hight='50' width='50'>";} print "<br>"; if($r['laston'] >= time()-15*60) { print "<font color=green>Online</font>"; } else { print"<font color=red>Offline</font>"; } print "</td> <td width='60%' colspan='2' valign='top' align='center' bgcolor='#CCCCCC'>".$bbc->bbcode_parse($r['mailtext'])."</td> </tr> </table> I'm trying to install a bbcode engine so that users can use bbcode in messages. Here is the complete script: <?php class bbcode { var $engine=""; function bbcode() { require "bbcode_engine.php"; $this->engine= new bbcode_engine; $this->engine->cust_tag("/</","<"); $this->engine->cust_tag("/>/",">"); //Since \n and <br> screw up preg, convert them out. $this->engine->cust_tag("/\n/","&nbrlb;"); $this->engine->simple_bbcode_tag("b"); $this->engine->simple_bbcode_tag("i"); $this->engine->simple_bbcode_tag("u"); $this->engine->simple_bbcode_tag("s"); $this->engine->simple_bbcode_tag("sub"); $this->engine->simple_bbcode_tag("sup"); $this->engine->simple_bbcode_tag("big"); $this->engine->simple_bbcode_tag("small"); $this->engine->adv_bbcode_tag("list","ul"); $this->engine->adv_bbcode_tag("olist","ol"); $this->engine->adv_bbcode_tag("item","li"); $this->engine->adv_option_tag("font","font","family"); $this->engine->adv_option_tag("size","font","size"); $this->engine->adv_option_tag("url","a","href"); $this->engine->adv_option_tag("color","font","color"); $this->engine->adv_option_tag("style","span","style"); $this->engine->simp_option_notext("img","src"); $this->engine->simp_bbcode_att("img","src"); $this->engine->cust_tag("/\(c\)/","©"); $this->engine->cust_tag("/\(tm\)/","™"); $this->engine->cust_tag("/\(r\)/","®"); $this->engine->adv_option_tag_em("email","a","href"); $this->engine->adv_bbcode_att_em("email","a","href"); $this->engine->cust_tag("/\[left\](.+?)\[\/left\]/","<div align='left'>\\1</div>"); $this->engine->cust_tag("/\[center\](.+?)\[\/center\]/","<div align='center'>\\1</div>"); $this->engine->cust_tag("/\[right\](.+?)\[\/right\]/","<div align='right'>\\1</div>"); $this->engine->cust_tag("/\[quote=(.+?)\](.+?)\[\/quote\]/","<div class='quotetop'>QUOTE(\\1)</div><div class='quotemain'>\\2</div>"); $this->engine->cust_tag("/\[quote\](.+?)\[\/quote\]/","<div class='quotetop'>QUOTE</div><div class='quotemain'>\\1</div>"); $this->engine->cust_tag("/\[code\](.+?)\[\/code\]/","<div class='codetop'>CODE</div><div class='codemain'><code>\\1</code></div>"); $this->engine->cust_tag("/\[codebox\](.+?)\[\/codebox\]/","<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>\\1</div>"); $this->engine->cust_tag("/&nbrlb;/","<br />\n"); } function bbcode_parse($html) { return $this->engine->parse_bbcode($html); } } function strip_html_tags($text) { return preg_replace("/<(.+?)>/is","", $text); } session_start(); require "global_func.php"; if($_SESSION['loggedin']==0) { header("Location: login.php");exit; } $userid=$_SESSION['userid']; require "header.php"; $h = new headers; $h->startheaders(); include "mysql.php"; global $c; $is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error()); $ir=mysql_fetch_array($is); check_level(); $fm=money_formatter($ir['money']); $cm=money_formatter($ir['crystals'],''); $lv=date('F j, Y, g:i a',$ir['laston']); $h->userdata($ir,$lv,$fm,$cm); $h->menuarea(); $bbc = new bbcode; if($ir['mailban']) { die("<font color=red><h3>! ERROR</h3> You have been mail banned for {$ir['mailban']} days.<br /> <br /> <b>Reason: {$ir['mb_reason']}</font></b>"); } $_GET['ID'] = abs((int) $_GET['ID']); print " <script language='JavaScript' type='text/javascript'><!-- // --><![CDATA[ var current_header = false; function shrinkHeader(mode) { document.getElementById('upshrinkHeader').style.display = mode ? 'none' : ''; document.getElementById('upshrinkHeader2').style.display = mode ? 'none' : ''; current_header = mode; } // ]]></script> <script language='JavaScript' type='text/javascript'><!-- // --><![CDATA[ var current_header_ic = false; function shrinkHeaderIC(mode) { document.getElementById('upshrinkHeaderIC').style.display = mode ? 'none' : ''; current_header_ic = mode; } // ]]></script> <table width=75% border=2><tr><td><a href='mailbox.php?action=inbox'>Inbox</a></td> <td><a href='mailbox.php?action=outbox'>Sent Messages</a></td> <td><a href='mailbox.php?action=compose'>Compose Message</a></td> <td><a href='mailbox.php?action=delall'>Delete All Messages</a></td> <td><a href='mailbox.php?action=archive'>Archive Messages</a></td></tr> </table><br />"; switch($_GET['action']) { case 'inbox': mail_inbox(); break; case 'outbox': mail_outbox(); break; case 'compose': mail_compose(); break; case 'delete': mail_delete(); break; case 'send': mail_send(); break; case 'delall': mail_delall(); break; case 'delall2': mail_delall2(); break; case 'archive': mail_archive(); break; default: mail_inbox(); break; } function mail_inbox() { global $ir,$c,$userid,$h; print "Only the last 25 messages sent to you are visible.<br /> <table width=75% border=2><tr style='background:silver'><th>Mail</th></tr>"; $q=mysql_query("SELECT m.*,u.* FROM mail m LEFT JOIN users u ON m.mail_from=u.userid WHERE m.mail_to=$userid ORDER BY mail_time DESC LIMIT 25",$c); while($r=mysql_fetch_array($q)) { $sent=date('F j, Y, g:i:s a',$r['mail_time']); print "<tr><td>"; if($r['userid']) { print " <table width='100%' cellpadding='0' cellspacing='0' border='0'> <tr height='32'> <td width='2%' align='left' bgcolor='#666666'><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]"; } else { print " <table width='100%' cellpadding='0' cellspacing='0' border='0'> <tr height='32'> <td width='2%' align='left' bgcolor='#666666'>SYSTEM"; } $fm=urlencode($r['mail_text']); print "</td> <td width='67%' align='center' bgcolor='#666666'>"; if ($r['mail_subject']){ print "{$r['mail_subject']}";} else { print "No subject";} print "</td> <td width='10%' align='right' bgcolor='#666666'><a href='#' onclick='shrinkHeader(!current_header); return false;'>Read</a></td> </tr> <tr id='upshrinkHeader' hight='80'><td width='20%' valign='middle' bgcolor='#CCCCCC'>"; if ($r['display_pic']){ print "<img src='{$r['display_pic']}' hight='50' width='50'>";} else { print "<img src='nopic.jpg' hight='50' width='50'>";} print "<br>"; if($r['laston'] >= time()-15*60) { print "<font color=green>Online</font>"; } else { print"<font color=red>Offline</font>"; } print "</td> <td width='60%' colspan='2' valign='top' align='center' bgcolor='#CCCCCC'>".$bbc->bbcode_parse($r['mailtext'])."</td> </tr> </table> <table id='upshrinkHeader2' width='100%' cellpadding='4' cellspacing='0' border='0'> <tr> <td width='20%' bgcolor='#666666'>Details of Message: </td><td width='40%' bgcolor='#666666'><a href='mailbox.php?action=compose&ID={$r['userid']}'>Reply</a> <a href='mailbox.php?action=delete&ID={$r['mail_id']}'>Delete</a> <a href='preport.php?ID={$r['userid']}&report=Fradulent mail: {$fm}'>Report</a></td> <td width='40%' align='right' valign='top' nowrap='nowrap' bgcolor='#666666'> Sent at: $sent<</td> </tr> </table> </div>"; } mysql_query("UPDATE mail SET mail_read=1 WHERE mail_to=$userid",$c); } function mail_outbox() { global $ir,$c,$userid,$h; print "Only the last 25 messages you have sent are visible.<br /> <table width=75% border=2><tr style='background:gray'><th>To</th><th>Subject/Message</th></tr>"; $q=mysql_query("SELECT m.*,u.* FROM mail m LEFT JOIN users u ON m.mail_to=u.userid WHERE m.mail_from=$userid ORDER BY mail_time DESC LIMIT 25",$c); while($r=mysql_fetch_array($q)) { $sent=date('F j, Y, g:i:s a',$r['mail_time']); print "<tr><td><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]</td><td>{$r['mail_subject']}</td></tr><tr><td>Sent at: $sent<br /></td><td>{$r['mail_text']}</td></tr>"; } } function mail_compose() { global $ir,$c,$userid,$h; print "<form action='mailbox.php?action=send' method='post'> <table width=75% border=2> <tr> <td>ID to send to:</td> <td><input type='text' name='userid' value='{$_GET['ID']}' /></td></tr><tr> <td>Subject:</td> <td><input type='text' name='subject' /></td></tr><tr> <td>Message:</td> <td><textarea rows=5 cols=40 name='message'></textarea></td></tr><tr> <td colspan=2><input type='submit' value='Send' /></td></tr></table></form>"; if($_GET['ID']) { print "<br /><table width=75% border=2><tr><td colspan=2><b>Your last 5 mails to/from this person:</b></td></tr>"; $q=mysql_query("SELECT m.*,u1.username as sender from mail m left join users u1 on m.mail_from=u1.userid WHERE (m.mail_from=$userid AND m.mail_to={$_GET['ID']}) OR (m.mail_to=$userid AND m.mail_from={$_GET['ID']}) ORDER BY m.mail_time DESC LIMIT 5",$c); while($r=mysql_fetch_array($q)) { $sent=date('F j, Y, g:i:s a',$r['mail_time']); print "<tr><td>$sent</td> <td><b>{$r['sender']} wrote:</b> {$r['mail_text']}</td></tr>"; } print "</table>"; } } function mail_send() { global $ir,$c,$userid,$h; $subj=str_replace(array("\n"),array("<br />"),strip_tags($_POST['subject'])); $msg=str_replace(array("\n"),array("<br />"),strip_tags($_POST['message'])); $to= (int) $_POST['userid']; mysql_query("INSERT INTO mail VALUES ('',0,$userid,$to,unix_timestamp(),'$subj','$msg')",$c) or die(mysql_error()); print "Message sent.<br /> <a href='mailbox.php'>> Back</a>"; } function mail_delete() { global $ir,$c,$userid,$h; mysql_query("DELETE FROM mail WHERE mail_id={$_GET['ID']} AND mail_to=$userid",$c); print "Message deleted.<br /> <a href='mailbox.php'>> Back</a>"; } function mail_delall() { global $ir,$c,$userid,$h; print "This will delete all the messages in your inbox.<br /> There is <b>NO</b> undo, so be sure.<br /> <a href='mailbox.php?action=delall2'>> Yes, delete all messages</a><br /> <a href='mailbox.php'>> No, go back</a>"; } function mail_delall2() { global $ir,$c,$userid,$h; mysql_query("DELETE FROM mail WHERE mail_to=$userid",$c); print "All ".mysql_affected_rows($c)." mails in your inbox were deleted.<br /> <a href='mailbox.php'>> Back</a>"; } function mail_archive() { global $ir,$c,$userid,$h; print "This tool will download an archive of all your messages.<br /> <a href='dlarchive.php?a=inbox'>> Download Inbox</a><br /> <a href='dlarchive.php?a=outbox'>> Download Outbox</a>"; } $h->endpage(); ?> Thanks For Reading Link to comment https://forums.phpfreaks.com/topic/43725-fatal-error-call-to-a-member-function-on-a-non-object/ Share on other sites More sharing options...
paul2463 Posted March 21, 2007 Share Posted March 21, 2007 where are you instantiating a new class bbcode object called $bbc ??? Link to comment https://forums.phpfreaks.com/topic/43725-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-212281 Share on other sites More sharing options...
DeathStar Posted March 21, 2007 Author Share Posted March 21, 2007 How do you mean? $bbc = new bbcode; ?? Link to comment https://forums.phpfreaks.com/topic/43725-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-212285 Share on other sites More sharing options...
paul2463 Posted March 21, 2007 Share Posted March 21, 2007 yes thats what I mean because your error as far as i can see is saying "I understand there is a function called bbcode_parse() but what you are calling it on is not a member of the class that can access it" if that makes sense Link to comment https://forums.phpfreaks.com/topic/43725-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-212287 Share on other sites More sharing options...
DeathStar Posted March 21, 2007 Author Share Posted March 21, 2007 Ok i understand but, how can i fix it? Link to comment https://forums.phpfreaks.com/topic/43725-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-212306 Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 function mail_inbox() { global $ir,$c,$userid,$h,$bbc; // add $bbc here. print "Only the last 25 messages sent to you are visible.<br /> <table width=75% border=2><tr style='background:silver'><th>Mail</th></tr>"; $q=mysql_query("SELECT m.*,u.* FROM mail m LEFT JOIN users u ON m.mail_from=u.userid WHERE m.mail_to=$userid ORDER BY mail_time DESC LIMIT 25",$c); while($r=mysql_fetch_array($q)) { $sent=date('F j, Y, g:i:s a',$r['mail_time']); print "<tr><td>"; if($r['userid']) { print " <table width='100%' cellpadding='0' cellspacing='0' border='0'> <tr height='32'> <td width='2%' align='left' bgcolor='#666666'><a href='viewuser.php?u={$r['userid']}'>{$r['username']}</a> [{$r['userid']}]"; } else { print " <table width='100%' cellpadding='0' cellspacing='0' border='0'> <tr height='32'> <td width='2%' align='left' bgcolor='#666666'>SYSTEM"; } $fm=urlencode($r['mail_text']); print "</td> <td width='67%' align='center' bgcolor='#666666'>"; if ($r['mail_subject']){ print "{$r['mail_subject']}";} else { print "No subject";} print "</td> <td width='10%' align='right' bgcolor='#666666'><a href='#' onclick='shrinkHeader(!current_header); return false;'>Read</a></td> </tr> <tr id='upshrinkHeader' hight='80'><td width='20%' valign='middle' bgcolor='#CCCCCC'>"; if ($r['display_pic']){ print "<img src='{$r['display_pic']}' hight='50' width='50'>";} else { print "<img src='nopic.jpg' hight='50' width='50'>";} print "<br>"; if($r['laston'] >= time()-15*60) { print "<font color=green>Online</font>"; } else { print"<font color=red>Offline</font>"; } print "</td> <td width='60%' colspan='2' valign='top' align='center' bgcolor='#CCCCCC'>".$bbc->bbcode_parse($r['mailtext'])."</td> </tr> </table> <table id='upshrinkHeader2' width='100%' cellpadding='4' cellspacing='0' border='0'> <tr> <td width='20%' bgcolor='#666666'>Details of Message: </td><td width='40%' bgcolor='#666666'><a href='mailbox.php?action=compose&ID={$r['userid']}'>Reply</a> <a href='mailbox.php?action=delete&ID={$r['mail_id']}'>Delete</a> <a href='preport.php?ID={$r['userid']}&report=Fradulent mail: {$fm}'>Report</a></td> <td width='40%' align='right' valign='top' nowrap='nowrap' bgcolor='#666666'> Sent at: $sent<</td> </tr> </table> </div>"; } mysql_query("UPDATE mail SET mail_read=1 WHERE mail_to=$userid",$c); } Link to comment https://forums.phpfreaks.com/topic/43725-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-212325 Share on other sites More sharing options...
DeathStar Posted March 21, 2007 Author Share Posted March 21, 2007 Ok thanks but can you please tell me how you fixed it? Link to comment https://forums.phpfreaks.com/topic/43725-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-212343 Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 global $ir,$c,$userid,$h,$bbc; // add $bbc here. $bbc needed to be global. Link to comment https://forums.phpfreaks.com/topic/43725-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-212344 Share on other sites More sharing options...
DeathStar Posted March 21, 2007 Author Share Posted March 21, 2007 Oh yes! forgot about those.. Thank you. Link to comment https://forums.phpfreaks.com/topic/43725-fatal-error-call-to-a-member-function-on-a-non-object/#findComment-212352 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.