gelite Posted September 24, 2011 Share Posted September 24, 2011 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. Quote Link to comment Share on other sites More sharing options...
Buddski Posted September 24, 2011 Share Posted September 24, 2011 You say it is failing miserably, can you provide us with any error details at all? Or what is actually happening when you call the function. Quote Link to comment Share on other sites More sharing options...
gelite Posted September 24, 2011 Author Share Posted September 24, 2011 There are no errors that show up, its just that nothing happens, which is what I meant by failing miserably. The page loads fine but cash does not get modified. Quote Link to comment Share on other sites More sharing options...
Buddski Posted September 24, 2011 Share Posted September 24, 2011 To do some basic testing I would echo out an error message before each of the return false; statements. This will give you and idea as to which part of the function isnt quite working and hone in on that section. Quote Link to comment Share on other sites More sharing options...
gelite Posted September 24, 2011 Author Share Posted September 24, 2011 Its much easier than that. The function is perfect, I'm asking how to make this correct: modify_cash_amount($poster_id, 1); Would it be written like this or something else? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.