I have a success page that displays some variables after a succesful transaction with Paypal (IPN).
It's all working great but I just can't figure out why the $email
variable does not echo out. Is there something wrong with the query? I have triple checked all the column names.
I get this output:
OK
price-1.89
Notice: Undefined variable: payer_email in success.php on line 34
Email-
Success.php
<?php
include 'dbConfig.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
//Get payment information from PayPal
$item_number= mysqli_real_escape_string($db, $_POST['item_number']);
$txn_id= mysqli_real_escape_string($db, $_POST['txn_id']);
$payment_gross= mysqli_real_escape_string($db, $_POST['payment_gross']);
//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){
//Get Email
$result = $db->query("SELECT payer_email FROM payments WHERE txn_id = '".$txn_id."'");
$row = $result->fetch_assoc();
$email=$row['payer_email'];
}
echo "OK</br>";
echo "Price-".$payment_gross."</br>";
echo "Email-".$email."</br>";
}else{
echo '<h1>Error</h1>';
}
?>