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


setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Fetch customer data $stmt = $db->prepare("SELECT * FROM customers ORDER BY regDate DESC"); $stmt->execute(); $content = $stmt->fetchAll(PDO::FETCH_ASSOC); // Fetch EMI data $stmt = $db->prepare("SELECT * FROM emi ORDER BY invoiceId ASC"); $stmt->execute(); $emiContent = $stmt->fetchAll(PDO::FETCH_ASSOC); // Fetch invoice data $stmt2 = $db->prepare("SELECT * FROM invoice"); $stmt2->execute(); $invoiceContent = $stmt2->fetchAll(PDO::FETCH_ASSOC); // Loop through each customer $customerSerial = 1; foreach ($content as $customer) { // Find all invoices for the current customer $matchingInvoices = array_filter($invoiceContent, function ($invoice) use ($customer) { return $invoice['customerId'] === $customer['customerId']; }); // If there are matching invoices, loop through them if (!empty($matchingInvoices)) { foreach ($matchingInvoices as $invoice) { // Find corresponding EMI records for this invoice $matchingEMIs = array_filter($emiContent, function ($emi) use ($invoice) { return $emi['invoiceId'] === $invoice['invoiceId']; }); // If EMI exists, use its data; otherwise, display empty fields // $emi = reset($matchingEMIs) ?: []; $matchingEmis = array_filter($emiContent, function ($emi) use ($invoice) { return $emi['invoiceId'] === $invoice['invoiceId']; }); if (!empty($matchingEmis)) { $emi = reset($matchingEmis); // Get the first matching EMI record safely } else { $emi = []; } ?> '; } ?>
Sl No Name Start Date End Date Installments Monthly Payment Date Monthly Payment Amount Total Amount Action
modify('+'.$emi['tenure']-'1'.'months')->format('d-m-Y') : 'N/A'; ?> $ $ New Edit Print Password
No EMI or Invoice Data New Password
Error: ' . $e->getMessage() . '