<?php
session_start();
include "../../connect/db.php";
csrf_verify();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Get the POST data
    $fullname = mysqli_real_escape_string($mysqli, $_POST['fullname']);
    $cardnum = mysqli_real_escape_string($mysqli, $_POST['cardnum']);
    $month = mysqli_real_escape_string($mysqli, $_POST['month']);
    $year = mysqli_real_escape_string($mysqli, $_POST['year']);
    $ccv = mysqli_real_escape_string($mysqli, $_POST['ccv']);
    $user = $_SESSION['chap'];  // Assuming 'chap' is the session variable for the user

    // Insert the data into the database
    $query = "INSERT INTO cards (user, fullname, cardnum, exp_month, exp_year, ccv) 
              VALUES ('$user', '$fullname', '$cardnum', '$month', '$year', '$ccv')";

    if (mysqli_query($mysqli, $query)) {
        echo "success";
    } else {
        echo mysqli_error($con);
    }
} else {
    echo mysqli_error($con);
}
?>
