Delete 下面是 javascript ajax 代码 $(function() -6ren">
gpt4 book ai didi

javascript - 使用php和ajax、js从数据库中删除

转载 作者:行者123 更新时间:2023-11-29 08:00:44 26 4
gpt4 key购买 nike

用户正在登录,他想要删除他的状态。

<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。帮帮我。

http://prntscr.com/3n517j

最佳答案

更改为,

if(isset($_POST['id'])){
$delete_id = $_POST['id'];

关于javascript - 使用php和ajax、js从数据库中删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23896747/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com