ppeasy/public/delete_ajax.php

47 lines
1.2 KiB
PHP

<?php
include('include/headscript.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$requiredParams = [
'id'
];
foreach ($requiredParams as $param) {
if (! in_array($param, array_keys($_POST)) || empty($_POST[$param])) {
$response = json_encode([
'status' => 'failed',
'message' => "Mandatory field is missing !({$param})"
]);
header('Content-Type: application/json');
echo $response;
exit();
}
}
$UpdateQuery = new WA_MySQLi_Query($cmctrfdb);
$UpdateQuery->Action = "delete";
$UpdateQuery->Table = "identificationparts";
$UpdateQuery->addFilter("ididentificationparts", "=", "i", "{$_POST['id']}");
try {
$UpdateQuery->execute();
$response = json_encode([
'status' => 'success'
]);
} catch (Exception $e) {
$response = json_encode([
'status' => 'failed',
'message' => $e->getMessage()
]);
}
} else {
$response = json_encode([
'status' => 'failed',
'message' => 'Method not allowed'
]);
}
header('Content-Type: application/json');
echo $response;