我有一个 php 文件,A.php
其中包含一个名为formA
.
得到结果然后formA
通过方法post并存储到MYSQLphp & SQL & traditional HTML form posting
中。
在其中的一个字段中formA
,我想将此值发布$amount
到另一个 php 文件。B.php
这是因为其中有一个隐藏的表单。B.php
我尝试使用php-curl
方法发布此内容以进行进一步的操作。
在中B.php
,我尝试测试是否可以$amount
成功。
两者都
print_r($_POST); print_r($_GET);
显示Array ( ) Array ( )
,这意味着未能获得amount
这是我的代码:
A.php:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Validate amount
$input_amount = trim($_POST["amount"]);
if (empty($input_amount)) {
$amount_err = "Please enter the amount.";
} elseif (!ctype_digit($input_amount)) {
$amount_err = 'Please enter a positive integer value.';
} else {
$amount = $input_amount;
}
//storing to db
if (empty($CName_err) && empty($Address_err) && empty($amount_err) && empty($Phone_err)) {
// Prepare an insert statement
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO donation (CName, Address, Phone, Amount ,Ticket, Purpose) VALUES (?, ?, ?, ? ,?, ?)";
$q = $pdo->prepare($sql);
$q->execute(array($CName, $Address, $Phone, $amount ,$Ticket ,$Purpose));
Database::disconnect();
//curl part start: post the `amount`
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"B.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"amount=amount,input_amount=input_amount");
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
header("Location: B.php");
}
}
?>
//Form A -the field that get the `amount` value
<div class="form-group <?php echo (!empty($amount_err)) ? 'has-error' : ''; ?>">
<label>* Donation amount</label>
<input list="amount" name="amount" multiple class="form-control">
<datalist id="amount" >
<option value="100">
<option value="300">
<option value="500">
<option value="1000">
</datalist>
<span class="help-block"><?php echo $amount_err; ?></span>
</div>
....other fields. ....
B.php:
<?php
print_r($_POST);
print_r($_GET);
$amount = null;
if ( !empty($_GET['amount'])) {
$amount = $_REQUEST['amount'];
}
...later action....
?>