Paypal payment failed.
Hi,
First of all, I am new to coding and do not know much about PHP and MySQL .
I am trying to implement PayPal transactions into my project but everytime I complete the checkout and I am redirected to my success.php file I get the message 'Your payment has failed'.
I am not sure how to get the script working.
<?php
include_once("config.php");
//Store transaction information into database from PayPal
$item_number = isset($_POST['item_number']) ? $_GET['item_number'] : null;
$txn_id = isset($_POST['tx']) ? $_GET['tx'] : null;
$payment_gross = isset($_POST['amt']) ? $_GET['amt'] : null;
$currency_code = isset($_POST['cc']) ? $_GET['cc'] : null;
$payment_status = isset($_POST['st']) ? $_GET['st'] : null;
//Get product price to store into database
$sql= "SELECT * price FROM `products` WHERE category_id = '1'";
$resultset = mysqli_query($db, $sql);
$row = mysqli_fetch_assoc($resultset);
if(!empty($txn_id) && $payment_gross == $row['price']){
//Insert tansaction data into the database
mysqli_query($db, "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 = mysqli_insert_id($db);
?>
<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
}
?>
I appreciate any help/advice you can give.
Thanks
Danyaal
