<?php
include("connection.php");
if (isset($_POST['update'])) {
   
    $id = $_POST['id'];

    // Check if a new file is uploaded
    if ($_FILES['upi_qr']['size'] > 0) {
        $upi_qr = $_FILES['upi_qr']['name'];
        $upi_qr_temp = $_FILES['upi_qr']['tmp_name'];
        $upi_qr_destination = 'img/' . $upi_qr;

        // Update the existing record, including the usdt_qr field
        $updateQuery = "UPDATE upi_payment SET  upi_qr = '$upi_qr' WHERE id='$id'";
        $updateResult = mysqli_query($conn, $updateQuery);

        if ($updateResult) {
            move_uploaded_file($upi_qr_temp, $upi_qr_destination);
            header("Location: upi_payment.php?msg=1"); // Updated successfully
            exit;
        } else {
            header("Location: upi_payment.php?msg=2"); // Failed to update
            exit;
        }
    } else {
    header("Location: upi_payment.php?msg=2"); // Failed to insert
    exit;
}
}

?>
