PHP文件和数组中$ _POST变量的错误

时间:2017-11-26 05:40:15

标签: php forms

当我将值硬编码到其中时,php文件正常工作。当我从html表单发帖子时,我可以正确看到变量,所以我知道他们正在传递给php文件。但是,当我将值的$ _POST用于硬编码值工作的位置时,脚本中出现错误。

以下是可用的硬编码值:

$accountID = "XXXXXXXX";
$secretKey = "XXXXXXXXXXXXX";
$mode = "TEST";

$payment = new BluePay(
    $accountID,
    $secretKey,
    $mode,
);

$payment->setCustomerInformation(array(
    'firstName' => 'Bob', 
    'lastName' => 'Tester', 
    'addr1' => '1234 Test St.', 
    'addr2' => 'Apt #500', 
    'city' => 'Testville', 
    'state' => 'IL', 
    'zip' =>'54321', 
    'country' => 'USA', 
    'phone' => '1231231234', 
    'email' => 'test@bluepay.com' 
));

这是带有$ _POST的改进的php表单。我正进入(状态 ;错误。我在设置和数组中正确调用了$​​ _POST吗?目前正在从处理器返回NAME错误,因为该名称未通过。

<?php

include('BluePay.php');

$payment = new BluePay(
    $_POST['accountID'], 
    $_POST['secretKey'],
    $_POST['mode']
);

$arrayVar = array(
        $firstName => $_POST['firstName'],
        $lastName => $_POST['lastName'],
        $addr1 => $_POST['addr1'],
        $addr2 => $_POST['addr2'],
        $city => $_POST['city'],
        $state => $_POST['state'],
        $zip => $_POST['zip'],
        $country => $_POST['country'],
        $phone => $_POST['phone'],
        $email => $_POST['email']
    );

$payment->setCustomerInformation($arrayVar);

$payment->setCCInformation(array(
    'cardNumber' => '4111111111111111', // Card Number: 4111111111111111
    'cardExpire' => '1217', // Card Expire: 12/15
    'cvv2' => '123' // Card CVV2: 123
));

/* $arrayVar2 = array(
    $cardNumber => $_POST['cardNumber'],
    $cardExpire => $_POST['cardExpire'], 
    $cvv2 => $_POST['cvv2'] 
);

$payment->setCCInformation($arrayVar2); */

$payment->sale('3.00'); // Sale Amount: $3.00 
//$payment['sale'] => $_POST['sale'];

 // Makes the API request with BluePay
$payment->process();

// Reads the response from BluePay
if($payment->isSuccessfulResponse()){
    echo 
    'Transaction Status: '. $payment->getStatus() . "\n" .
    'Transaction Message: '. $payment->getMessage() . "\n" .
    'Transaction ID: '. $payment->getTransID() . "\n" .
    'AVS Response: ' . $payment->getAVSResponse() . "\n" .
    'CVS Response: ' . $payment->getCVV2Response() . "\n" .
    'Masked Account: ' . $payment->getMaskedAccount() . "\n" .
    'Card Type: ' . $payment->getCardType() . "\n" .
    'Authorization Code: ' . $payment->getAuthCode() . "\n";
} else{
    echo $payment->getMessage() . "\n";
}
?>

这是html表单

<html>
<body>

<form action="ccpost.php" method="post">
<input type="hidden" name="accountID" value="XXXXXXXXXX" />
<input type="hidden" name="secretKey" value="XXXXXXXXXXX />
<input type="hidden" name="mode" value="TEST" />
First Name: <input type="text" name="firstName"><br>
Last Name: <input type="text" name="lastName"><br>
Address 1: <input type="text" name="addr1"><br>
Address 2: <input type="text" name="addr2"><br>
City: <input type="text" name="city"><br>
State: <input type="text" name="state"><br>
Zip Code: <input type="text" name="zip"><br>
Country: <input type="text" name="country"><br>
Phone: <input type="text" name="phone"><br>
E-mail: <input type="text" name="email"><br>
Card Number: <input type="text" name="cardNumber"><br>
Card Expire: <input type="text" name="cardExpire"><br>
Cvv: <input type="text" name="cvv2"><br>
Sale: <input type="text" name="sale"><br>
<input type="submit">
</form>

</body>
</html> 

0 个答案:

没有答案