Jump to content

Simple function problem


gelite

Recommended Posts

I'm trying to use a function from my phpbb forum but failing, function looks like this:

 

	/*
* Modify a users cash.
* $action -> 0 = add, 1 = subtract, 2 = set.
*/
function modify_cash_amount($user_id, $amount, $dbfield='user_points', $action=0) {
	global $db;
	$sql = "SELECT * FROM " . CASH_DATA_TABLE . " WHERE user_id = '" . $user_id . "'";
	$result = $db->sql_query($sql);
	if ($result) {
		$row = $db->sql_fetchrow($result);
		if ($row) {
			switch ($action) {
				case 1:
					$amount = $row[$dbfield] - $amount;
				break;

				case 2:
					$amount = $amount;
				break;

				default:
					$amount = $row[$dbfield] + $amount;
				break;
			}
			$sql = "UPDATE " . CASH_DATA_TABLE . " SET " . $dbfield . " = '" . $amount . "' WHERE `user_id` = '" . $user_id . "' LIMIT 1";
			$result = $db->sql_query($sql);
			if ($result) {
				return true;
			}
			else {
				return false;
			}
		}
		else {
			return false;
		}
	}
	else {
		return false;
	}
}

 

The way I understand it, the function takes a $user_id, modifies his cash by $amount in $dbfield which by default is 'user_points' and action is explained in the comment. However when I try applying it I fail miserably. I'm working from the file viewtopic.php in phpBB and I need to add 1 cash to the OP of the topic.

 

Phpbb files and viewtopic can be downloaded from here: http://www.phpbb.com/files/release/phpBB-3.0.9.zip

 

I'm not sure how to enter OP into the function. I think $poster_id gives it but applying it like this does not work:

modify_cash_amount($poster_id, 1);

 

I'm assuming leaving the latter two out is fine if they have standard values.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.