用户登录,他想删除他的状态。
<p><?php echo $status; ?></p> //this shows status
<a href="" id="<?php echo $upid; ?>" class="delete">Delete</a>
这里是javascript ajax代码
<script type="text/javascript" >
$(function() {
$(".delete").click(function(){
var del_id = element.attr("id");
var info = 'id=' + del_id;
if(confirm("Sure you want to delete this update? There is NO undo!"))
{
$.ajax({
type: "POST",
url: "delete.php",
data: info,
success: function(){
}
});
$(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow");
}
return false;
});
});
</script>
这是我的delete.php
<?php
include("includes/db_connect.php");
if(isset($_GET['id'])){
$delete_id = $_GET['id'];
$delete_query = "delete from user_posts where upid='$delete_id'";
mysqli_query($con, $delete_query);
}
?>
用户个人资料链接是profile.php?id = 1此ID是用户ID ..不是帖子ID ..当我将鼠标移动到删除按钮时,在底部显示个人资料ID,而不是删除ID。帮助我。
答案 0 :(得分:1)
type: "POST",
将其更改为“GET”。
否则你将无法在$ _GET中找到该值。
答案 1 :(得分:1)
更改为,
if(isset($_POST['id'])){
$delete_id = $_POST['id'];