Jump to content

[SOLVED] PHP Fatal error: Call to a member function doForm() on a non-object in H:\www\f


SNN

Recommended Posts

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!

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

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!

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();

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.