<?php
session_start();
include "dbconnect.php"; // Database connection

// Check if the 'delete' parameter is set
if (isset($_GET['delete'])) {
    $payment_id = $_GET['delete'];  // Get the payment ID to delete

    // Prepare and execute the DELETE SQL query
    $sql_delete = "DELETE FROM clientspayment WHERE id = ?";
    if ($stmt = $con->prepare($sql_delete)) {
        $stmt->bind_param("i", $payment_id);  // Bind the payment_id parameter
        if ($stmt->execute()) {
            // If successful, redirect with success message
            $_SESSION['message'] = "Payment record deleted successfully.";
            header("Location: clientpaymentlist.php");
        } else {
            // If an error occurs, display an error message
            $_SESSION['error'] = "Error: " . $con->error;
            header("Location: clientpaymentlist.php");
        }
        $stmt->close();  // Close the prepared statement
    } else {
        $_SESSION['error'] = "Error preparing SQL query: " . $con->error;
        header("Location: clientpaymentlist.php");
    }
} else {
    // If 'delete' parameter is not set, redirect with an error message
    $_SESSION['error'] = "No record specified for deletion.";
    header("Location: clientpaymentlist.php");
}

$con->close();  // Close the database connection
?>
