Sending a delte.php properly to my db

别等时光非礼了梦想. 提交于 2019-12-13 08:05:44

问题


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


回答1:


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>



回答2:


You mean something like

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

Bobby




回答3:


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.



来源:https://stackoverflow.com/questions/1662337/sending-a-delte-php-properly-to-my-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!