无法将数据保存到我的数据库。它显示“此页面无效”。我已在我的索引中插入<input type='text' name='return' value='http://www.xxxx.com.my/paypal/paypal_success.php'>
。但是在成功付款后仍无法将数据保存到我的数据库中。
<?php
include 'connection.php';
//save Trasaction information form PayPal
$item_number = $_GET['item_number'];
$txn_id = $_GET['Trasaction_ID'];
$payment_gross = $_GET['AMT'];
$currency_code = $_GET['CURRENCY_CODE'];
$payment_status = $_GET['PAYMENT_STATUS'];
//Get product price
$productResult = $db->query("SELECT price FROM products WHERE id = ".$item_number);
$productRow = $productResult->fetch_assoc();
$productPrice = $productRow['price'];
if(!empty($txn_id) && $payment_gross == $productPrice){
//Check if payment data exists with the same TXN ID.
$prevPaymentResult = $db->query("SELECT payment_id FROM payments WHERE txn_id = '".$txn_id."'");
if($prevPaymentResult->num_rows > 0){
$paymentRow = $prevPaymentResult->fetch_assoc();
$last_insert_id = $paymentRow['payment_id'];
}else{
//Insert tansaction data into the database
$insert = $db->query("INSERT INTO payments(item_number,txn_id,payment_gross,currency_code,payment_status) VALUES('".$item_number."','".$txn_id."','".$payment_gross."','".$currency_code."','".$payment_status."')");
$last_insert_id = $db->insert_id;
}
?>
<h1>Your payment has been successful.</h1>
<h1>Your Payment ID - <?php echo $last_insert_id; ?>.</h1>
<?php
}else{
?>
<h1>Your payment has failed.</h1>
<?php
}
?>