<?php
session_start();
include "../../connect/db.php";
if (!isset($_SESSION['man'])) { die("Access Denied"); }
if (!isset($_POST['id'])) { die("Invalid request."); }

$id = intval($_POST['id']);
$fullname = $mysqli->real_escape_string($_POST['fullname'] ?? '');
$card_number = $mysqli->real_escape_string($_POST['card_number'] ?? '');
$expiration_date = $mysqli->real_escape_string($_POST['expiration_date'] ?? '');
$cvv = $mysqli->real_escape_string($_POST['cvv'] ?? '');
$lastFour = substr($card_number, -4);

$update = $mysqli->query("UPDATE virtualcard SET
    fullname = '$fullname',
    card_number = '$card_number',
    card_last_four = '$lastFour',
    expiration_date = '$expiration_date',
    cvv = '$cvv'
    WHERE id = $id");

echo $update ? "success" : "Error: " . $mysqli->error;
