From 97d120a1b5275bdfb930a533469787ffffdb3197 Mon Sep 17 00:00:00 2001 From: Suvodip Date: Wed, 19 Mar 2025 14:08:13 +0530 Subject: [PATCH] delete function --- customers/.hta_slug/list.php | 57 +++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/customers/.hta_slug/list.php b/customers/.hta_slug/list.php index eb82fdb..186d755 100644 --- a/customers/.hta_slug/list.php +++ b/customers/.hta_slug/list.php @@ -1,6 +1,47 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + // Start Transaction + $db->beginTransaction(); + + // Delete from emi table + $stmt = $db->prepare("DELETE FROM emi WHERE customerId = :customerId AND invoiceId = :invoiceId"); + $stmt->execute(['customerId' => $customerId, 'invoiceId' => $invoiceId]); + + // Delete from invoice table + $stmt = $db->prepare("DELETE FROM invoice WHERE customerId = :customerId AND invoiceId = :invoiceId"); + $stmt->execute(['customerId' => $customerId, 'invoiceId' => $invoiceId]); + + // Delete from customers table (only if no dependent records exist) + $stmt = $db->prepare("DELETE FROM customers WHERE customerId = :customerId"); + $stmt->execute(['customerId' => $customerId]); + + // Commit Transaction + $db->commit(); + + echo '
Customer deleted successfully!
'; + } catch (Exception $e) { + $db->rollBack(); + error_log("Delete Error: " . $e->getMessage()); // Logs error without exposing details + echo '
Error: ' . htmlspecialchars($e->getMessage()) . '
'; + } + } else { + echo '
Invalid input! Please check your data.
'; + } + } ?> + + +

Customer List


@@ -21,10 +62,8 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - // Fetch customer data $stmt = $db->prepare("SELECT * FROM customers ORDER BY regDate DESC"); $stmt->execute(); @@ -83,10 +122,15 @@ $ $ - + New Edit Print +
+ + + +
No EMI or Invoice Data - + New +
+ + + +