Darkmatter5 Posted March 18, 2009 Share Posted March 18, 2009 Here's the error message "Fatal error: Call to a member function getusername() on a non-object in /home2/thealien/public_html/veintrade/library/vein_cpm.php on line 65" Here's vein_funcs.php <?php class vein { function getusername($userid) { $query="SELECT mem_username FROM members WHERE member_id='$userid' LIMIT 1"; $result=mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result)) { $row=mysql_fetch_array($result); return $row[0]; } else { return "Unknown"; } } } ?> Here's vein_cpm.php <?php require_once('library/vein_funcs.php'); $vein=new vein(); class vein_cpm { var $messages=array(); var $dateformat=''; function getmessage($message) { $query="SELECT * FROM user_messages WHERE message_id='$message' AND (author='$_SESSION[member_id]' OR recipient='$_SESSION[member_id]') LIMIT 1"; $result=mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result)) { $this->messages=array(); $row=mysql_fetch_assoc($result); $this->messages[0]['message_id']=$row['message_id']; $this->messages[0]['title']=$row['title']; $this->messages[0]['content']=$row['content']; $this->messages[0]['author']=$row['author']; $this->messages[0]['recipient']=$row['recipient']; $this->messages[0]['aut_name']=$vein->getusername($row['author']); $this->messages[0]['rec_name']=$vein->getusername($row['recipient']); $this->messages[0]['aut_viewed']=$row['aut_viewed']; $this->messages[0]['rec_viewed']=$row['rec_viewed']; $this->messages[0]['aut_deleted']=$row['aut_deleted']; $this->messages[0]['rec_deleted']=$row['rec_deleted']; $this->messages[0]['auth_vdate']=date($this->dateformat, strtotime($row['aut_vdate'])); $this->messages[0]['rec_vdate']=date($this->dateformat, strtotime($row['rec_vdate'])); $this->messages[0]['auth_ddate']=date($this->dateformat, strtotime($row['aut_ddate'])); $this->messages[0]['rec_ddate']=date($this->dateformat, strtotime($row['rec_ddate'])); $this->messages[0]['created_date']=date($this->dateformat, strtotime($row['created_date'])); } else { return false; } } } ?> These are the lines in vein_cpm.php that produce the error $this->messages[0]['aut_name']=$vein->getusername($row['author']); $this->messages[0]['rec_name']=$vein->getusername($row['recipient']); What could be causing this? I hope I've included enough code. Link to comment https://forums.phpfreaks.com/topic/149974-help-with-fatal-error/ Share on other sites More sharing options...
Zhadus Posted March 18, 2009 Share Posted March 18, 2009 Not positive, but try putting: require_once('library/vein_funcs.php'); $vein=new vein(); inside of the class? Link to comment https://forums.phpfreaks.com/topic/149974-help-with-fatal-error/#findComment-787620 Share on other sites More sharing options...
Darkmatter5 Posted March 18, 2009 Author Share Posted March 18, 2009 Well here's what I tried. New vein_cpm.php <?php require_once('library/vein_funcs.php'); class vein_cpm { var $messages=array(); var $dateformat=''; function getmessage($message) { $vein=new vein(); //Moved this line inside the function. $query="SELECT * FROM user_messages WHERE message_id='$message' AND (author='$_SESSION[member_id]' OR recipient='$_SESSION[member_id]') LIMIT 1"; $result=mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result)) { $this->messages=array(); $row=mysql_fetch_assoc($result); $this->messages[0]['message_id']=$row['message_id']; $this->messages[0]['title']=$row['title']; $this->messages[0]['content']=$row['content']; $this->messages[0]['author']=$row['author']; $this->messages[0]['recipient']=$row['recipient']; $this->messages[0]['aut_name']=$vein->getusername($row['author']); $this->messages[0]['rec_name']=$vein->getusername($row['recipient']); $this->messages[0]['aut_viewed']=$row['aut_viewed']; $this->messages[0]['rec_viewed']=$row['rec_viewed']; $this->messages[0]['aut_deleted']=$row['aut_deleted']; $this->messages[0]['rec_deleted']=$row['rec_deleted']; $this->messages[0]['auth_vdate']=date($this->dateformat, strtotime($row['aut_vdate'])); $this->messages[0]['rec_vdate']=date($this->dateformat, strtotime($row['rec_vdate'])); $this->messages[0]['auth_ddate']=date($this->dateformat, strtotime($row['aut_ddate'])); $this->messages[0]['rec_ddate']=date($this->dateformat, strtotime($row['rec_ddate'])); $this->messages[0]['created_date']=date($this->dateformat, strtotime($row['created_date'])); } else { return false; } } } ?> This works, but I don't want to have to put this line inside every function I need to call this class. Can't I make a global usage of this class? Link to comment https://forums.phpfreaks.com/topic/149974-help-with-fatal-error/#findComment-787633 Share on other sites More sharing options...
Zhadus Posted March 18, 2009 Share Posted March 18, 2009 You could do: $GLOBALS['vein']=new vein(); Outside of the class and function. Link to comment https://forums.phpfreaks.com/topic/149974-help-with-fatal-error/#findComment-787648 Share on other sites More sharing options...
waynew Posted March 18, 2009 Share Posted March 18, 2009 Try <?php require_once('library/vein_funcs.php'); $vein=new vein(); class vein_cpm { private $messages=array(); private $dateformat=''; private $vein = NULL; function __construct($vein_obj){ $this->vein = $vein_obj; } function getmessage($message) { $query="SELECT * FROM user_messages WHERE message_id='$message' AND (author='$_SESSION[member_id]' OR recipient='$_SESSION[member_id]') LIMIT 1"; $result=mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result)) { $this->messages=array(); $row=mysql_fetch_assoc($result); $this->messages[0]['message_id']=$row['message_id']; $this->messages[0]['title']=$row['title']; $this->messages[0]['content']=$row['content']; $this->messages[0]['author']=$row['author']; $this->messages[0]['recipient']=$row['recipient']; $this->messages[0]['aut_name']=$this->vein->getusername($row['author']); $this->messages[0]['rec_name']=$this->vein->getusername($row['recipient']); $this->messages[0]['aut_viewed']=$row['aut_viewed']; $this->messages[0]['rec_viewed']=$row['rec_viewed']; $this->messages[0]['aut_deleted']=$row['aut_deleted']; $this->messages[0]['rec_deleted']=$row['rec_deleted']; $this->messages[0]['auth_vdate']=date($this->dateformat, strtotime($row['aut_vdate'])); $this->messages[0]['rec_vdate']=date($this->dateformat, strtotime($row['rec_vdate'])); $this->messages[0]['auth_ddate']=date($this->dateformat, strtotime($row['aut_ddate'])); $this->messages[0]['rec_ddate']=date($this->dateformat, strtotime($row['rec_ddate'])); $this->messages[0]['created_date']=date($this->dateformat, strtotime($row['created_date'])); } else { return false; } } } ?> Link to comment https://forums.phpfreaks.com/topic/149974-help-with-fatal-error/#findComment-787653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.