在我删除帐户之前,我想知道是否有任何Hiringorg和/或转移链接到该帐户。
如果还有Hiringorg和/或转移,那么我想得到一个警告说:首先删除Hiringorg和/或转移。
我到底该怎么做?
AJAX
//Function of the delete button inside the Modal.
$('button#delete').click(function() { //delete comes from id='Delete' on line 166 in index.php
var id=$('input#deleteID').val(); //deleteID comes from id='deleteID' on line 162 in index.php
$.ajax({
method: "POST",
dataType: "json",
url: "ajax.php",
data: {
id:id,
action:"deleteAccount"
},
success: function (result) {
if (result.status){
location.reload();
}else{
alert("Please remove the HiringOrg and/or Transfer.")
}
}
});
});
Jquery的
function deleteAccount($id){
global $conn;
$checkHir = $conn->prepare("
SELECT *
FROM cfg_hiringorg
WHERE account_id =".$id);
$checkHir->execute();
$checkTrans = $conn->prepare("
SELECT *
FROM cfg_transfer
WHERE account =".$id);
$checkTrans->execute();
if (!$checkTrans AND !$checkHir) {
$stmt = $conn->prepare("DELETE FROM cfg_accounts WHERE id=".$id);
$stmt->execute();
$success = $stmt->rowCount() ? true : false;
return ['status' => $success];
}
}