开发者

deleting a comment you posted with php code?

开发者 https://www.devze.com 2023-04-13 00:05 出处:网络
I was wondering if you can maybe help me out here... I created a link sharing website and managed to create a comment on a shared link.

I was wondering if you can maybe help me out here... I created a link sharing website and managed to create a comment on a shared link.

I want to give you a scenario of what I would like to achieve. Every comment made by user_1 for instance, can only be deleted by user_1 and admin.

I understand that when "deleting" it from the php page it must also be dropped from the database. How can you do this?

//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'开发者_如何学C]) . ",
                " . $_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!';
}


Your Delete query has major syntax errors. You don't delete individual fields from a table - you CAN'T. you can only delete entire records. The proper syntax is:

DELETE FROM sometable WHERE (...)

Your where clause also has errors. You're not doing any comparison operations, just listing some values. Again, a syntax error. Most like you'd want this (guessing at your post's table primary key field name):

DELETE FROM posts WHERE (post_id = $id);


You should give your comments ID's, and simply perform delete from posts where ID = $id.

The SQL statement you currently have won't even execute. Look at the manual for how the syntax works.


What would really be helpful is some separation of presentation logic from db logic from bus. logic. Try a MVC pattern, which makes it a lot easier to parse through the code and to only look at DB or presentation or bus. logic code. Then, we could focus on the answer to the question posted.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号