0

I am developing a small form in which the user can register using PayPal payment. but the problem is the user information is not storing in the database after the successful payment. Here is the code for insert

$db = new mysqli($dbConfig['host'], $dbConfig['username'], $dbConfig['password'], $dbConfig['name']);

// Assign posted variables to local data array.
$data = [
    'item_name'        => $_POST['item_name'],
    'item_number'      => $_POST['item_number'],
    'payment_status'   => $_POST['payment_status'],
    'payment_amount'   => $_POST['mc_gross'],
    'payment_currency' => $_POST['mc_currency'],
    'txn_id'           => $_POST['txn_id'],
    'receiver_email'   => $_POST['receiver_email'],
    'payer_email'      => $_POST['payer_email'],
    'custom'           => $_POST['custom'],
];

if(verifyTransaction($_POST) && checkTxnid($data['txn_id'])) {
    if(addPayment($data) !== FALSE) {
    }
}


function addPayment($data)
{
    global $db;
    if(is_array($data)) {
        $stmt = $db->prepare('INSERT INTO `payments` (txnid, payment_amount, payment_status, itemid, payer_email) VALUES( ?, ?, ?, ?, ?)');
        $stmt->bind_param(
            'sdsss',
            $data['txn_id'],
            $data['payment_amount'],
            $data['payment_status'],
            $data['item_number'],
            $data['payer_email']
        );
        $stmt->execute();
        $stmt->close();

        return $db->insert_id;
    }

    return FALSE;
}
aynber
  • 22,380
  • 8
  • 50
  • 63
jaiswal
  • 1
  • 2
  • Check for [mysqli errors](http://php.net/manual/en/mysqli.error.php) after your bind and execute to verify that the query is working correctly. – aynber Jul 22 '19 at 20:27

1 Answers1

-2

remove single quotes from payments INSERT INTO payments and change this itemid to item_number in table values above.

ZaHid
  • 81
  • 8