data not storing in database

65 views Asked by At

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;
}
1

There are 1 answers

0
ZaHid On

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