PHP Script Not Writing Bankfee To Database

The attached file, credits.php, is part of our new (experimental) banking / credits system for this site.

I added a field bankfee in credits_transactions but it is not writing to the database (no PHP error).

Can someone take a look at the attached PHP file and see if they can find out why bankfee in the database table credits_transactions does not update from the initialized value of zero?

/* Neo: original
                $db->query_write("INSERT INTO " . TABLE_PREFIX . "credits_transactions (fromuserid, touserid, action, anonymous, comment, amount, timestamp, completed) VALUES (" . $vbulletin->userinfo['userid'] . ", " . $duser['userid'] . ", 'donate', " . $vbulletin->GPC['anonymous'] . ", '" . $db->escape_string(fetch_censored_text($vbulletin->GPC['comment'])) . "', " . $vbulletin->GPC['amount'] . ", " . TIMENOW . ", " . intval($notmoderated) . ")");
*/
                $db->query_write("INSERT INTO " . TABLE_PREFIX . "credits_transactions (fromuserid, touserid, action, anonymous, comment, amount, bankfee, timestamp, completed) VALUES (" . $vbulletin->userinfo['userid'] . ", " . $duser['userid'] . ", 'donate', " . $vbulletin->GPC['anonymous'] . ", '" . $db->escape_string(fetch_censored_text($vbulletin->GPC['comment'])) . "', " . $vbulletin->GPC['amount'] . ", " . $vbulletin->GPC['bankfee'] . ", " . TIMENOW . ", " . intval($notmoderated) . ")");

Hi Neo,

If I traced correctly, the part you mentioned will be triggered by the donate form from the user CP. However, I fail to locate any form parameter matching the name "bankfee", where the code is trying to perform some sentry of the form data.

I suggest you print_r($vbulletin->GPC) after clean_array_gpc() and verify whether you still have the "bankfee" key and bear a non-zero value. My guess is that there is none. You can use error_log() to write the output to PHP log file (if configured).

Thanks for replying. I agree with you.

FWIW,

The donate form is here.

http://www.unix.com/credits.php

And the donation processing is performed with:

http://www.unix.com/credits.php?do=donate

$bankfee is calculated:


$vbulletin->input->clean_array_gpc('p', array(
		'amount'	=> TYPE_UNUM,
		'fee'	=> TYPE_UNUM,
		'bankfee'	=> TYPE_UNUM,
		'recipient'	=> TYPE_NOHTML,
		'comment'	=> TYPE_NOHTML,
		'anonymous'	=> TYPE_BOOL
	));

	$amount = $transferred = $vbulletin->GPC['amount'];
	$donatefee = $vbulletin->GPC['amount'] * $vbulletin->options['credits_donatefee'];
	//$bankfee = $vbulletin->GPC['donatefee'];
	$bankfee = $donatefee;

[/COLOR]

The code in red was added my me ....

There will be no value (or maybe zero, initialized) for $bankfee immediately after clean_array_gpc() because $bankfee is calucated after clean_array_gpc().

So since $donatefee = $bankfee that means passing $vbulletin->GPC['bankfee'] to $db->query_write() does not work, but when I do:

//$bankfee = $vbulletin->GPC['donatefee'];

I get an error and the script fails.

What should I pass to $db->query_write() ?

-----Post Update-----

Hi cbkihong,

OK, it working fine now, thanks for the hints.

I replaced:

$vbulletin->GPC['bankfee'] in $db->query_write() with $bankfee

and it works fine :smiley:

Easy fix, thanks for unfogging my weary brain!

Glad you figured it out. Thanks for confirming you indeed modified some additional code as I thought that variable should not have been passed from outside the server, obviously, for security reasons.

It's time for bed for me. Same for you! :wink:

Oh! I forgot you are one hour ahead of me in HK.

Thanks again and goodnight. I will not be working on code much for the next 10 days, vacation time!

Our embryonic Bits Bank is now recording the bankfees in credits_transactions :smiley: