我有一个带有相应删除按钮的行列表。当用户单击删除按钮时,必须删除该行。
我的html按钮作为表格的一部分。我检查了是否将正确的ID传递给了函数。
<td style="border-color: #f3e0d7" ><button name="btn_delete" class="deleteSub" onclick="DeleteSubscription('.$row["RSS_ID"].')" >Delete</button></td>
javascript的DeleteSubscription按钮
function DeleteSubscription(id){
alert(id);
if(confirm("Are you sure you want to remove this subscription?")){
$.ajax({
url:'LandingPage.php',
method:"POST",
date:
{
delete_Subscription:1,
idPHP:id,
},
success:function(response){
alert(response);
fetch_data();
},
dataType:"text",
});
}
};
我的用于与表通信的PHP代码
if(isset($_POST['delete_Subscription'])){
$ID = !empty($_POST['idPHP']) ? trim($_POST['idPHP']) : null;
try{
$connect = mysqli_connect($servername,$username,$password,$database);
$sql=("DELETE FROM rssfeeds WHERE RSS_ID='".$ID."'");
if(mysqli_query($connect,$sql)){
exit('Subscription deleted');
}
else{
print_r($sql->errorInfo());
exit('error');
}
}catch(PDOException $e){
console.log($e);
}
}