Skip to main content
danyaalk74530408
Known Participant
March 10, 2017
Question

Paypal payment failed.

  • March 10, 2017
  • 1 reply
  • 1130 views

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

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    March 10, 2017

    The code you've posted has a space in payment_status:

    VALUES('".$item_number."','".$txn_id."','".$payment_gross."','".$currency_code."','".$pay ment_status."')");

    Are you following the steps outlined at codexworld: PayPal Standard Payment Gateway Integration in PHP - CodexWorld ?

    danyaalk74530408
    Known Participant
    March 11, 2017

    Hi,

    I've removed the space and the issue still remains.

    I am following their tutorial but no matter what I try I still get the same message.

    Thanks

    Danyaal,