SNN Posted March 4, 2007 Share Posted March 4, 2007 A few friends and I am making a new forum software and we don't have a clue what non-object means.. Any help? This is the issue: PHP Fatal error: Call to a member function doForm() on a non-object in H:\www\forum\index.php on line 360 And this is a chunk of the code: // Defining // Topic class class topic { function doForm($title) { if(!$_SESSION['username']) { echo('You must login to post topics/replies!'); } echo('<fieldset><legend>'.$title.'</legend> <form method="POST" name="newtopic" action="index.php?x=newtopic&process=1"> Topic Title:<br /> <input type="text" name="title" /><br /> <input type="submit" value="Create Topic!" /> </form>'); } function doProcess() { $sql = "INSERT INTO topics (`toptitle`) VALUES ( `".$_POST['title']."` );"; $msclass->DB->query($sql); } } // Line 360 elseif($x == "newtopic") { if($_GET['process'] == 1) { function doProcess($toptitle) { $sql = "INSERT INTO topics (`memid`,`toptitle`) VALUES (`".$username."`,`".$toptitle."`);"; } $topic->doProcess(); } else { $topic->doForm('Start New Topic'); // This is line 360 } Any help is appricated. Thanks! Link to comment https://forums.phpfreaks.com/topic/41142-solved-php-fatal-error-call-to-a-member-function-doform-on-a-non-object-in-hwwwf/ Share on other sites More sharing options...
utexas_pjm Posted March 4, 2007 Share Posted March 4, 2007 This line of code is calling the method doForm on the instance $topic. $topic->doForm('Start New Topic'); There is no reference named $topic, an object can reference itself by using $this. So I think you want the above code to look like: $this->doForm('Start New Topic'); Link to comment https://forums.phpfreaks.com/topic/41142-solved-php-fatal-error-call-to-a-member-function-doform-on-a-non-object-in-hwwwf/#findComment-199279 Share on other sites More sharing options...
SNN Posted March 4, 2007 Author Share Posted March 4, 2007 So basically there is no $topic? My friend said there was a defined one >_> I did see $post defined though. EDIT: my-friend: WT* I did define the class topic! me: so basically it deleted its self? my-friend: idk lol me: lol I guess he will be redefining it soon. Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/41142-solved-php-fatal-error-call-to-a-member-function-doform-on-a-non-object-in-hwwwf/#findComment-199284 Share on other sites More sharing options...
utexas_pjm Posted March 4, 2007 Share Posted March 4, 2007 Sorry... I misread your code.... The $topic->doForm is outside of the class.... in which case you musty explicitely define a calss instance... like this: $topic = new topic(); // then you can do... $topic->doForm(); Link to comment https://forums.phpfreaks.com/topic/41142-solved-php-fatal-error-call-to-a-member-function-doform-on-a-non-object-in-hwwwf/#findComment-199291 Share on other sites More sharing options...
SNN Posted March 4, 2007 Author Share Posted March 4, 2007 Ah, ok. Thanks, this is really helpful with what I am doing with this software Link to comment https://forums.phpfreaks.com/topic/41142-solved-php-fatal-error-call-to-a-member-function-doform-on-a-non-object-in-hwwwf/#findComment-199294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.