Jump to content

Call to class error undefined $obj


son.of.the.morning

Recommended Posts

Alright guys got a but of a issue here, i keep geting a 'Call to class error undefined $obj' and i cant seem to see the problem.

 

my class

<?php

class DatabaseInsert {

	function ArticleInsert($table,$fields,$values) {

		$values_imploded = implode("','",$values);
		$fields_imploded = implode(",",$fields);
		$i = "INSERT INTO $table ($fields_imploded) VALUES ($values_imploded)";

		mysql_query($i) or die( "<br>Query string: <br>Produced error: " . mysql_error() );;
		//$table,$fields,$values

	}
}



?>

 

The call

if(isset($_POST['sub'])) {

					include("../scrips/php/cms/database.insert.class.php");
					$table = "blog_posts";
					$title = "'".$_POST['ArticleTitle']."'";
					$img = "'2'";
					$post = "'".$_POST['ArticleBody']."'";
					$aurthor_id = "'1'";
					$category_id = "'4'";
					$date_posted = "NOW()";

					$values = array("$title","$img","$post","$aurthor_id","$category_id","$date_posted");
					$fields = array('title','img','post','aurthor_id','category_id','date_posted'); 
					//echo $values['0']."<br/>".$fields['0'];

					echo $values['0']."<br/>".$values['1']."<br/>".$values['2']."<br/>".$values['3']."<br/>".$values['4']."<br/>".$values['5'];
					$obj->ArticleInsert($table,$fields,$values);

Link to comment
Share on other sites

You can't invoke a method unless one of two things happens:

 

1. You instantiate a new object of the type you want to use, i.e.:

 

$obj = new DatabaseInsert();
$obj -> ArticleInsert($table, $fields, $values);

 

2. You declare the method as static:

 

class DatabaseInsert
{
   public static function ArticleInsert($table, $fields, $values)
   {
      // blah
   }
}

// ...

DatabaseInsert::ArticleInsert($table, $fields, $values);

 

That said, what you're attempting to do isn't very OOP.  You're not gaining anything by simply stuffing your function in a class.  Grouping functions by theme is not OOP, regardless of whether or not you use classes and objects.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.