I am trying to make my entry be deleted from the website but it is not working. after a full review, I still did not see the error . I bought the codes online and tyring to repurpose it from its original purpose. but even with the stock scripts the entry is not deleting. the the file in question are as follows;
<tbody>
<?php
$sql = "SELECT * FROM crypto_currency ORDER BY crypto_name ";
$stmt = $conn->prepare($sql);
$stmt->execute();
$sn=1;
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$id = $row['id'];
?>
<tr>
<td><?= $sn++ ?></td>
<td><?= $row['crypto_name'] ?></td>
<td><?= $row['wallet_address'] ?></td>
<td><?= $row['created_at'] ?></td>
<td class="text-center"><a class="btn btn-primary edit-crypto" data-name="<?= $row['crypto_name'] ?>" data-wallet-address="<?= $row['wallet_address'] ?>" data-id="<?= $row['id']?>">Update</a> </td>
<td>
<form action="./crypto-currrency.php" method="post" >
<input type="text" hidden name="crypto_id" value="<?=$row['id']?>">
<button class="btn btn-danger delete-crypto-currency" data-id="<?= $row['id'] ?>" name="delete" ><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x-circle text-white"><circle cx="12" cy="12" r="10"></circle><line x1="15" y1="9" x2="9" y2="15"></line><line x1="9" y1="9" x2="15" y2="15"></line></svg></button>
</form></td>
</tr>
<?php
}
?>
enter image description here
<script>
function toast(msg,type){
return swal({
type: type,
title: type,
text: msg,
padding: "2em"
});
}
$(".delete-crypto-currency").on('click',function(e){
e.preventDefault();
let crypto_id = $(this).data('id');
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Delete',
padding: '2em'
}).then(function(result) {
if (result.value) {
$.ajax({
url : '<?= APP_URL.'admin/crypto-currrency.php'?>',
type : 'post',
dataType : 'json',
data : {
'delete_crypto_currency' : '',
'crypto_currency_id' : crypto_id
},
},
timeout : 45000,
success : function(data){
console.log(data);
if(data.error == 1){
toast(data.msg,'success');
}else{
toast(data.msg,'error');
}
setTimeout(function(){
window.location.href='<?= APP_URL.'admin/crypto-currrency.php'?>';
},1000)
},
error : function(er){
// console.log(er.responseText);
toast('error network','error');
}
});
}
})
});
</script>
<?php
if(isset($_POST['delete_crypto_currency'])){
require './include/adminloginFunction.php';
$crypto_id = $_POST['crypto_currency_id'];
$del = $conn->prepare("DELETE FROM crypto_currency WHERE id =:id");
$del->execute(['id'=>$crypto_id]);
if($del){
echo json_encode(['error'=>'1','msg'=>'Action successfully']);
}else{
echo json_encode(['error'=>'0','msg'=>'Cant delete']);
}
exit;
}
When i checked the network logs it wasnt doing through.
i was asked to check the network console to see the feedback
attached is an image to show the feedback i was getting.
like i stated previously, i am a beginner and wouldnt understand the technical terms much. Kindly bare with and bring it down to a lame’s man understanding… thanks
