从数据库中删除使用php和ajax,js

从数据库中删除使用php和ajax,js

问题描述:

User is login and he want to delete his status.

<p><?php echo $status; ?></p> //this shows status
<a href="" id="<?php echo $upid; ?>" class="delete">Delete</a> 

here is javascript ajax code below

<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>

and this is my 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);
}

?>

User profile link is profile.php?id=1 This id is user ID.. not post ID.. when i move my mouse to delete button, at the bottom it shows profile id, not delete id. help me out.

http://prntscr.com/3n517j

用户登录后他想删除自己的状态。 p>

 &lt; p&gt;&lt;?php echo $ status;  ?&GT;&LT; / p为H.  //这显示状态
&lt; a href =“”id =“&lt;?php echo $ upid;?&gt;” 类= “删除” &GT;删除&LT; / A&GT;  
  code>  pre> 
 
 

这里是javascript ajax代码 p>

 &lt; script type =“text / javascript”&gt; \  n $(function(){
 
 $(“。delete”)。click(function(){
var del_id = element.attr(“id”); 
var info ='id ='+ del_id; \  nif(确认(“当然你要删除此更新?没有撤消!”))
 {
 $ .ajax({
type:“POST”,
url:“delete.php”,
data:  info,
success:function(){
} 
}); 
 $(this).parents(“。record”)。animate({backgroundColor:“#fbc7c7”},“fast”)
。  animate({opacity:“hide”},“slow”); 
} 
return false; 
}); 
}); 
&lt; / script&gt; 
  code>  pre> 
  
 

这是我的delete.php p>

 &lt;?php 
include(“includes / db_connect.php”);  
 
if(isset($ _ GET ['id'])){
 $ delete_id = $ _GET ['id']; 
 
 $ delete_query =“从user_posts删除,其中up​​id ='$ delete_id'”;  
 
mysqli_query($ con,$ delete_query); 
} 
 
?&gt; 
  code>  pre> 
 
 

用户个人资料链接是profile.php?id = 1 这个id是用户ID ..不是帖子ID ..当我将鼠标移动到删除按钮时,在底部显示配置文件ID,而不是删除ID。 帮助我。 p>

http://prntscr.com/3n517j div>

Change to,

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

type: "POST",

change this to "GET".

Otherwise you won't find the value in $_GET.