set_charset("utf8"); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Get agent list $getAgentListsQuery = "SELECT * FROM " . $GLOBALS['arif_users']; $agentResult = $conn->query($getAgentListsQuery); $agentList = []; if ($agentResult && $agentResult->num_rows > 0) { while ($row = $agentResult->fetch_assoc()) { $agentList[] = $row; } } // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { $collectableLoanAmount = isset($_POST['COLLECTABLE_LOAN_AMOUNT']) ? floatval($_POST['COLLECTABLE_LOAN_AMOUNT']) : 0; $collectableRecurringAmount = isset($_POST['COLLECTABLE_RECURRING_AMOUNT']) ? floatval($_POST['COLLECTABLE_RECURRING_AMOUNT']) : 0; $collectableAgent = isset($_POST['COLLECTABLE_AGENT']) ? $_POST['COLLECTABLE_AGENT'] : null; if (($collectableLoanAmount > 0 || $collectableRecurringAmount > 0) && $collectableAgent) { $stmt = $conn->prepare(" INSERT INTO agent_collections ( agent, collectable_loan_amount, collected_loan_amount, collectable_recurring_amount, collected_recurring_amount, date ) VALUES (?, ?, 0, ?, 0, CURDATE()) "); $stmt->bind_param("sdd", $collectableAgent, $collectableLoanAmount, $collectableRecurringAmount); if ($stmt->execute()) { echo "