У меня есть серверный код на PHP:
Код: Выделить всё
function delete($customer_id)
{
if ($this->db->query("DELETE "
. "FROM _customer "
. 'WHERE customer_id = ?;', array('customer_id' => $customer_id))) {
return ['result' => 'OK'];
} else {
return ['result' => $this->db->error()];
}
}
Код: Выделить всё
function deleteRow(customer_id) {
if (confirm("Da li ste sigurni da želite da brišete odabranu stavku?")) {
overlay.style.display = 'block';
webservice({
'proc': 'Customer',
'CallbackFunction': function (r) {
overlay.style.display = 'none';
const json = JSON.parse(r["data"]);
if (json.result === "OK") {
select();
} else {
showToast("Greška", json.result, "error").classList.remove("bg-dark");
}
},
'errorCallbackFunction': function (r) {
overlay.style.display = 'none';
if (r && r.error && r.error.message) {
showToast("Greška 468", r.error.message, "error").classList.remove("bg-dark");
} else {
showToast("Greška 468", "Došlo je do greške molim probajte ponovo ili osvežite stranicu.", "error").classList.remove("bg-dark");
}
},
'data': JSON.stringify({
"function": "delete",
"customer_id": customer_id
})
});
}
Где веб-сервис — это просто оболочка для функции выборки JavaScript.
И ошибка:
Код: Выделить всё
Error Number: 1451
Cannot delete or update a parent row: a foreign key constraint fails (`orange`.`_order`, CONSTRAINT `order_customer_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `_customer` (`customer_id`) ON UPDATE CASCADE)
DELETE FROM _customer WHERE customer_id = 1;
Filename: D:/aaa/system/database/DB_driver.php
Line Number: 691
Подробнее здесь: https://stackoverflow.com/questions/726 ... the-client
Мобильная версия