douning5041 2017-11-26 00:31
浏览 63

将数据从HTML表单发布到PHP操作脚本

I can get the .php file to work with the sample data in it. However, I have tried several ways to get an html form to post the variables into the php. What is the best way to do this? I am attaching the .php with the sample data in it that works on the site. When I try to use an .html file and post to this it stops at the BluPay.php file and nothing happens and the transaction fails to send the data. This is only test data so nothing is real inside for credit card information.

<?php
/**
* BluePay PHP Sample Code
*
* This code sample runs a $3.00 Credit Card Sale transaction
* against a customer using test payment information.
* If using TEST mode, odd dollar amounts will return
* an approval and even dollar amounts will return a decline.
*
*/

include('BluePay.php');

$accountID = "XXXXXXXX";
$secretKey = "XXXXXXXXXXXXXX";
$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' 
));

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

$payment->sale('3.00'); // Sale Amount: $3.00

 // 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 one of the html I was using to post to the php above after I removed the values:

<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>

This is the current php I am trying to post to. So I took the variables and use the $_POST. However I am getting an PHP Parse error: syntax error, unexpected ';' around the accountID line.

<?php

include('BluePay.php');

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

$payment->setCustomerInformation(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->setCCInformation(array(
    'cardNumber' => '4111111111111111', // Card Number: 4111111111111111
    'cardExpire' => '1217', // Card Expire: 12/15
    'cvv2' => '123' // Card CVV2: 123
));

$payment->sale('3.00'); // Sale Amount: $3.00

 // 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() . "
";
}
?>
  • 写回答

1条回答 默认 最新

  • duanhui3759 2017-11-26 00:44
    关注

    since I can't see your .html file, it's not so easy to provide you a specific answer. But the best I can do is to recommend you this tutorial: https://www.w3schools.com/php/php_forms.asp There you should find everything.

    Basicly you have to put your .php script to an 'action tag' of your .html, use method GET or POST and then in .php take the data from globals $_GET or $_POST.

    评论

报告相同问题?

悬赏问题

  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗