删除您用PHP代码发布的评论


deleting a comment you posted with php code?

我想知道你是否可以帮助我在这里…我创建了一个链接分享网站,并设法在一个共享的链接上创建一个评论。

我想给你一个我想要实现的场景。例如,user_1的每条评论,只能被user_1和admin删除。

我明白,当"删除"它从php页面,它也必须从数据库中删除。你怎么能这么做?

//I pressume where I INSERTED my post's 'vales' I must DELETE them again from there??
//It is very much alike from reply.php's code where you INSERT the data into the database. Now I just want to delete it.
//I don't know if this code below is correct??
$sql = "DELETE FROM 
            posts(post_content,
                  post_date,
                  post_topic,
                  post_by) 
        WHERE ('" . $_POST['reply-content'] . "',
                NOW(),
                " . mysql_real_escape_string($_GET['id']) . ",
                " . $_SESSION['user_id'] . ")";

$result = mysql_query($sql);
if(!$result)
{
    echo 'Your reply has not been saved, please try again later.';
}
else
{
    echo 'Your comment has been deleted!';
}

您的Delete查询有重大语法错误。你不能从表中删除单个字段——你不能。您只能删除整个记录。正确的语法是:

DELETE FROM sometable WHERE (...)

where子句也有错误。你没有做任何比较操作,只是列出一些值。还是一个语法错误。最像你想要这样(猜测你的帖子的表主键字段名):

DELETE FROM posts WHERE (post_id = $id);

您应该给出您的注释ID,并简单地执行delete from posts where ID = $id

当前的SQL语句甚至不会执行。

真正有用的是将表示逻辑与数据库逻辑与总线逻辑分离。逻辑。尝试MVC模式,它使解析代码变得容易得多,并且只查看DB或表示或总线。逻辑代码。然后,我们可以专注于问题的答案张贴。