繁体   English   中英

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

[英]Posting data from HTML form to the PHP action Script

我可以将.php文件与其中的示例数据一起使用。 但是,我尝试了几种方法来获取html表单以将变量发布到php中。 做这个的最好方式是什么? 我将.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解析错误:语法错误,意外的';' 在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文件,因此很难为您提供特定的答案。 但是,我能做的最好的就是向您推荐本教程: https : //www.w3schools.com/php/php_forms.asp您应该在那里找到所有内容。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM