douzuanze0486 2017-11-26 05:40
浏览 48

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

The php file works correctly when I hard code the values into it. When I do a post from the html form I can see the variables correctly so I know they are passing to the php file. However, I am getting errors in the script when I use the $_POST of the values into the places where the hard coded values work.

Here is the hard coded values that work:

$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' 
));

Here is the altered php form with the $_POST. I am getting ; errors in it. Am I calling the $_POST correctly in the setup and arrays? Currently getting NAME error which is coming back from the processor for the name not passing through.

<?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() . "
" .
    'Transaction Message: '. $payment->getMessage() . "
" .
    'Transaction ID: '. $payment->getTransID() . "
" .
    'AVS Response: ' . $payment->getAVSResponse() . "
" .
    'CVS Response: ' . $payment->getCVV2Response() . "
" .
    'Masked Account: ' . $payment->getMaskedAccount() . "
" .
    'Card Type: ' . $payment->getCardType() . "
" .
    'Authorization Code: ' . $payment->getAuthCode() . "
";
} else{
    echo $payment->getMessage() . "
";
}
?>

Here is the html form

<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> 
  • 写回答

1条回答 默认 最新

  • dongsi2317 2017-11-26 06:02
    关注

    There seems an error in your PHP, below is the updated:

    $payment = new BluePay(
        $_POST['accountID'], // you don't need to  $accountID = $_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);
    
    评论

报告相同问题?

悬赏问题

  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取
  • ¥15 vue3+element-plus页面崩溃