I'm testing a success page that loads after a transaction with paypal(ipn) has succesfully been completed. All data is succesfully saved to a database at the ipn stage but for some reason the success page I'm using does not load any variables I have fetched. In this case $last_insert_id
The only thing that is echoed is the word success
BUT when I hit reload the variable appears. Can someone explain what I have gotten wrong. Thanks.
Success.php
<?php
include 'dbconnection.php';
//Get payment information from PayPal
$item_number = $_GET['item_number'];
$txn_id = $_GET['tx'];
$payment_gross = $_GET['amt'];
$currency_code = $_GET['cc'];
$payment_status = $_GET['st'];
$item_name = $_GET['item_name'];
//Get product price from database
$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'];
}
echo "success";
echo $last_insert_id;
} else{
echo "error";
}
?>