Sending a delte.php properly to my db

2019-09-20 04:42发布

I have a function on my that has a delete button to erase comments. I have the button all linked up and ready to go. I just don't know what I should put on the 'delte.php' script I am creating, and what to tell it php wise to send to the db to make the status dead. as well as deleting the comment off of the page.

Thanks

3条回答
别忘想泡老子
2楼-- · 2019-09-20 05:24

You mean something like

mysql_query("DELETE * FROM yourTable WHERE commentId = $id", $yourDbLink);

Bobby

查看更多
ゆ 、 Hurt°
3楼-- · 2019-09-20 05:25

Your php script would contain a query to delete the comment

mysql_query("delete from comments where id = $id");

Send a request using Ajax which won't reload the current webpage. Here is a snippet using jQuery

function deleteComment(commentId)
{
$.ajax({
   type: "POST",
   url: "delete.php",
   data: "id="+ commentId,
   success: function(msg){
     alert( "Comment " + commentId + " deleted" );
   }
 });
}

<a href="#" onclick="deleteComment(1)">Delete Comment 1</a>
查看更多
趁早两清
4楼-- · 2019-09-20 05:33

If you do not want the browser to go anywhere you could send HTTP status 204, "No content".

Typically though you'd do a redirect to the same page with a notice saying "Comment deleted." or similar.

查看更多
登录 后发表回答