0

This page will delete a post:

require_once ('db.php');
$db = new DB();
$db->deletePost($_GET['id'], $_GET['postType']);

db.php only contains a class which called DB and its functions.

this is a part of db.php:

public function deleteComment($post_id, $post_type)
{
    $query = "delete from t_comments where c_type = '$post_type' and c_id = '$post_id';";
    $this->execute($query);
}
public function deletePost($post_id, $post_type)
{
    deleteComment($post_id, $post_type);
    $query = "delete from t_news where n_id = '$post_id';";
    $this->execute($query);
}

Then mysql says: Fatal error: Call to undefined function deletecomment() in db.php on line 70

I defined deleteComment above the deletePost!So what's the problem?Can't I call another function of a class in that class?But in C++, I think it is possible!

2
  • 1
    Side note: you better read up on SQL injection Commented Jan 12, 2012 at 12:16
  • 1
    Another side-note, don't use GET for your database manipulations; it might cause a search engine or a browser accelerator to wipe out your database. Commented Jan 12, 2012 at 12:20

2 Answers 2

3

deleteComment(… -> $this->deleteComment(…

You should give PDO a try mate!

Sign up to request clarification or add additional context in comments.

Comments

2

Use this:

$this->deleteComment($post_id, $post_type);

instead of

deleteComment($post_id, $post_type);

2 Comments

thanks a lot! It worked! But why it is required to use $this->... ?does it mean execute the function which is in "THIS" class?
Because PHP does not know which context to use withou $this, so it will use global scope.In global scope you don't have function with this signature, so it will raise error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.