2012-01-12 73 views
0

該頁面將刪除帖子:未定義功能在MySQL和PHP

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

db.php中只包含一類稱爲DB和它的功能。

這是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); 
} 

那麼MySQL說: 致命錯誤:調用未定義的函數deletecomment()在db.php中上線70

我定義deleteComment以上deletePost!那麼是什麼問題?我不能在該類中調用另一個類的函數嗎?但是在C++中,我認爲這是可能的!

+1

旁註:你更好的'SQL讀了injection' – bububaba 2012-01-12 12:16:55

+1

另一個側面說明,沒有爲自己的數據庫中使用'GET'操作;它可能會導致搜索引擎或瀏覽器加速器清除數據庫。 – jeroen 2012-01-12 12:20:45

回答

2

使用此:中

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

代替

deleteComment($post_id, $post_type); 
+0

非常感謝!有效!但爲什麼需要使用$ this - > ...?這是否意味着執行「THIS」類中的函數? – 2012-01-12 12:21:45

+2

由於PHP不知道使用哪個上下文$ this,因此它將使用全局範圍。在全局範圍中,您沒有此簽名的功能,因此會引發錯誤。 – rkosegi 2012-01-12 12:23:52

3

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

你應該給PDO一試隊友!