setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $customerId = $_POST['customerId']; $totalAmount = $_POST['totalAmount']; $tenure = min($_POST['tenure'], 18); // Limit tenure to 18 months $firstEmiDate = $_POST['firstEmiDate']; $emiAmount = $totalAmount / $tenure; // Prepare the query dynamically $columns = ['customerId', 'totalAmount', 'tenure', 'emiAmount', 'firstEmiDate']; $placeholders = [':customerId', ':totalAmount', ':tenure', ':emiAmount', ':firstEmiDate']; $params = [ ':customerId' => $customerId, ':totalAmount' => $totalAmount, ':tenure' => $tenure, ':emiAmount' => $emiAmount, ':firstEmiDate' => $firstEmiDate ]; // Add EMI columns dynamically based on tenure for ($i = 1; $i <= $tenure; $i++) { $emiDate = date('Y-m-d', strtotime("+$i months", strtotime($firstEmiDate))); $columns[] = "emi$i"; $columns[] = "emi{$i}Date"; $placeholders[] = ":emi$i"; $placeholders[] = ":emi{$i}Date"; $params[":emi$i"] = $emiAmount; $params[":emi{$i}Date"] = $emiDate; } // Construct SQL statement $sql = "INSERT INTO billing (" . implode(',', $columns) . ") VALUES (" . implode(',', $placeholders) . ")"; $stmt = $db->prepare($sql); // Execute the query if ($stmt->execute($params)) { echo '
New EMI plan for ' . htmlspecialchars($customerId) . ' saved successfully.
'; } else { echo '
Error executing statement: ' . $stmt->errorInfo()[2] . '
'; } } catch (PDOException $e) { echo '
Error: ' . $e->getMessage() . '
'; } } // Fetch customer details $customer = null; if (!empty($_GET['customerId'])) { try { $db = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $db->prepare("SELECT * FROM customers WHERE customerId = :customerId"); $stmt->bindParam(':customerId', $_GET['customerId']); if ($stmt->execute()) { $customer = $stmt->fetch(PDO::FETCH_ASSOC); } } catch (PDOException $e) { echo '
Error: ' . $e->getMessage() . '
'; } } ?>

EMI Calculation

Name:

Mobile:

Customer not found.