【问题标题】:Posting data from HTML form to the PHP action Script将数据从 HTML 表单发布到 PHP 操作脚本
【发布时间】:2017-11-26 00:31:59
【问题描述】:

我可以让 .php 文件使用其中的示例数据。但是,我尝试了几种方法来获取一个 html 表单以将变量发布到 php.ini 中。做这个的最好方式是什么?我正在附加 .php,其中包含适用于该站点的示例数据。当我尝试使用 .html 文件并将其发布到此文件时,它会在 BluPay.php 文件处停止,并且没有任何反应,并且交易无法发送数据。这只是测试数据,因此信用卡信息内部没有任何内容。

<?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() . "\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";
}
?>

这是我在删除值后用来发布到上述 php 的 html 之一:

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

这是我要发布到的当前 php。所以我接受了变量并使用了 $_POST.但是我收到一个 PHP Parse 错误:语法错误,意外的 ';'在 accountID 行周围。

<?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() . "\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代码
  • 发布表单中的标记。
  • 您确定您在表单操作中使用了正确的文件名??? ccpost.php???
  • 您没有访问 PHP 文件中的任何 $_POST 数据
  • 如果文件正确,可能你应该在php文件的开头检查你是否通过print_r($_POST)接收到$_POST数组中的数据;

标签: php html forms payment-gateway


【解决方案1】:

由于我看不到您的 .html 文件,因此很难为您提供具体的答案。但我能做的最好的就是向您推荐本教程: https://www.w3schools.com/php/php_forms.asp 在那里你应该找到所有东西。

基本上你必须把你的 .php 脚本放到 .html 的“动作标签”中,使用方法 GET 或 POST,然后在 .php 中从全局变量 $_GET 或 $_POST 中获取数据。

【讨论】:

  • 那么我可以获取变量并像这样调用它们 $firstName = ($_POST['firstName'];
  • 是的,像这样:$firstName = $_POST["firstName"]; 你在 html 表单中的输入应该有一个标签 name="firstName"(你已经有这样的了,我写它只是为了说明清楚)。跨度>
  • 我收到一个意外错误; $payment = new BluePay( $accountID = $_POST["accountID"]; $secretKey = $_POST["secretKey"]; $mode = $_POST["mode"]; );
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-05
  • 1970-01-01
  • 2017-04-27
  • 2022-01-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多