是的,這是可能的,但你應該只發送條目的id到一個特定的頁面來刪除entry.never整個sql語句。
<button id="<?php echo $row['id']; ?>" class="delbutton"></button>
這個腳本添加到您的網頁
<script type="text/javascript" >
$(function() {
$(".delbutton").click(function() {
var del_id = $(this).attr("id");
var info = 'id=' + del_id;
if (confirm("Sure you want to delete this post? This cannot be undone later.")) {
$.ajax({
type : "POST",
url : "delete_entry.php", //URL to the delete php script
data : info,
success : function() {
}
});
$(this).parents(".record").animate("fast").animate({
opacity : "hide"
}, "slow");
}
return false;
});
});
</script>
最後,但沒有起碼你的刪除腳本
<?php
include 'connection.php';
$id=$_POST['id'];
$delete = "DELETE FROM table WHERE id=$id";
$result = mysql_query($delete) or die(mysql_error());
?>
是。你需要搜索ajax。 – jeroen 2014-10-20 14:29:32
你不應該「發送一個sql語句」。 YOu可以向服務器發送一條指令,告訴它刪除一條特定的記錄,但是你的客戶端應用程序不應該在sql級別處理任何事情。考慮有人搞清楚你的「run sql」查詢語法,並通過http://example.com/dosql.php?sql=drop數據庫databasename()'「oops」發送。 – 2014-10-20 14:36:27
「發送一條sql語句」我認爲它是不言而喻的,一個sql查詢將是PDO或mysqli。 – 2014-10-20 14:47:30