vigiw Posted September 12, 2006 Share Posted September 12, 2006 Hi everyone, I am working on a system here to subtract or add points from users. I have a working MySQL database running with phpBB (Integramod) and a points system is installed in the database. Many of the members on the message board have some amount of points. I want to create a PHP file or a few PHP files (if needed) to have a form where the user can "purchase" items with points, such as website advertising, or whatever else. I would need it to subtract the necessary amount of points from user_points in the phpbb_users table. Does anyone have any suggestions? This would be a great addition and I would like to show it to everyone as soon as possible. I am not a good coder but this may be of some use to reference from: pointscp.php: [code]<?php/*************************************************************************** * pointscp.php * ------------------- * begin : Sunday, April 14, 2002 * copyright : (C) 2002 Bulletin Board Mods * email : [email protected] * * ***************************************************************************//*************************************************************************** * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * ***************************************************************************/define('IN_PHPBB', true);$phpbb_root_path = './';include($phpbb_root_path . 'extension.inc');include($phpbb_root_path . 'common.'.$phpEx);include($phpbb_root_path . 'includes/functions_points.'.$phpEx);//// Start session management//$userdata = session_pagestart($user_ip, PAGE_INDEX);init_userprefs($userdata);//// End session management////// Program Start//if (isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode'])){ $mode = (isset($HTTP_POST_VARS['mode'])) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];}else{ $mode = '';}$user_id = (isset($HTTP_GET_VARS[POST_USERS_URL])) ? intval($HTTP_GET_VARS[POST_USERS_URL]) : 0;$template->set_filenames(array( 'body' => 'points_system.tpl'));//Startif ($mode == 'donate'){ if ($userdata['user_id'] == ANONYMOUS) { $redirect = "pointscp.$phpEx&mode=donate"; $redirect .= (isset($user_id)) ? '&' . POST_USERS_URL . '=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if (!$board_config['points_donate']) { message_die(GENERAL_MESSAGE, $lang['Points_user_donation_off']); } if (isset($HTTP_POST_VARS['submit'])) { if(!empty($HTTP_POST_VARS['username'])) { $user_id = get_userid_from_name($HTTP_POST_VARS['username']); if (empty($user_id)) { $error = true; $error_msg = $lang['No_such_user']; } if ($user_id == $userdata['user_id']) { $error = true; $error_msg .= ((!empty($error_msg)) ? '<br />' : '') . sprintf($lang['Points_cant_donate_self'], $board_config['points_name']); } } else { $error = true; $error_msg = $lang['Points_no_username']; } if (abs(intval($HTTP_POST_VARS['amount'])) == 0) { $error = true; $error_msg .= ((!empty($error_msg)) ? '<br />' : '') . sprintf($lang['Points_enter_some_donate'], $board_config['points_name']); } if (isset($error)) { $template->set_filenames(array( 'reg_header' => 'error_body.tpl') ); $template->assign_vars(array( 'ERROR_MESSAGE' => $error_msg) ); $template->assign_var_from_handle('ERROR_BOX', 'reg_header'); } else { $amount = abs(intval($HTTP_POST_VARS['amount'])); $from_points = get_user_points($userdata['user_id']); if ($amount > $from_points) { message_die(GENERAL_MESSAGE, sprintf($lang['Points_cant_donate'], $board_config['points_name'])); } add_points($user_id, $amount); subtract_points($userdata['user_id'], $amount); //Send doation email if the user wants it $sql = "SELECT username, user_lang, user_email, user_notify_donation FROM " . USERS_TABLE . " WHERE user_id = $user_id"; if (!$result = $db->sql_query($sql)) { message_die(GENERAL_ERROR, "Could not get username & user_notify_donation & user_lang & user_email", '', __LINE__, __FILE__, $sql); } $to_userdata = $db->sql_fetchrow($result); if ($to_userdata['user_notify_donation']) { include($phpbb_root_path . 'includes/emailer.'.$phpEx); $emailer = new emailer($board_config['smtp_delivery']); $email_headers = 'From: ' . $board_config['board_email'] . "\nReturn-Path: " . $board_config['board_email'] . "\n"; $emailer->use_template('user_notify_donation', $to_userdata['user_lang']); $emailer->email_address($to_userdata['user_email']); $emailer->extra_headers($email_headers); $emailer->assign_vars(array( 'DONATOR' => $userdata['username'], 'USERNAME' => $to_userdata['username'], 'AMOUNT_DONATE' => $amount, 'TOTAL_POINTS' => get_user_points($user_id), 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $board_config['board_email_sig']), 'L_POINTS' => $board_config['points_name']) ); $emailer->send(); $emailer->reset(); } $loc = (!empty($HTTP_POST_VARS['location'])) ? $HTTP_POST_VARS['location'] : append_sid("pointscp.$phpEx?mode=donate"); $template->assign_vars(array( 'META' => '<meta http-equiv="refresh" content="3;url=' . $loc . '">') ); $msg = $lang['Points_thanks_donation'] . '<br /><br />' . sprintf($lang['Click_return_points_donate'], '<a href="' . append_sid("pointscp.$phpEx?mode=donate") . '">', '</a> ') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>'); message_die(GENERAL_MESSAGE, $msg); } } $s_username = (!empty($user_id)) ? get_username_from_id($user_id) : ''; $location = (empty($HTTP_POST_VARS['location'])) ? $HTTP_SERVER_VARS['HTTP_REFERER'] : $location; $s_hidden_fields = '<input type="hidden" name="location" value="' . $location . '">'; $template->assign_vars(array( 'L_FIND_USERNAME' => $lang['Find_username'], 'L_SUBMIT' => $lang['Submit'], 'L_RESET' => $lang['Reset'], 'L_POINTS_TITLE' => $lang['Points_donation'], 'L_DONATE_TO' => sprintf($lang['Points_donate_to'], $board_config['points_name']), 'L_AMOUNT' => $lang['Points_amount'], 'L_AMOUNT_GIVE' => sprintf($lang['Points_give'], $board_config['points_name']), 'USERNAME' => $s_username, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_POST_ACTION' => append_sid("pointscp.$phpEx?mode=donate", true), 'U_SEARCH_USER' => append_sid("search.$phpEx?mode=searchuser")) ); $template->assign_block_vars('switch_points_donate', array());}else{ if ($userdata['user_id'] == ANONYMOUS) { $redirect = "pointscp.$phpEx"; $redirect .= (isset($user_id)) ? '&user_id=' . $user_id : ''; header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true)); } if ($userdata['user_level'] != ADMIN && user_is_authed($userdata['user_id']) == false) { message_die(GENERAL_MESSAGE, $lang['Points_not_admin']); } if (isset($HTTP_POST_VARS['submit'])) { if (empty($HTTP_POST_VARS['username']) && empty($HTTP_POST_VARS['mass_username'])) { $error = true; $error_msg .= $lang['Points_no_username']; } else { $user_id = get_userid_from_name($HTTP_POST_VARS['username']); if (empty($user_id) && empty($HTTP_POST_VARS['mass_username'])) { $error = true; $error_msg = $lang['No_such_user']; } else { $user_id_list = array(); $user_id_list[] = $user_id; if (!empty($HTTP_POST_VARS['mass_username'])) { $mass_usernames = explode("\n", $HTTP_POST_VARS['mass_username']); foreach ($mass_usernames as $username) { $username = trim($username); if (!empty($username)) { $user_id_list[] = get_userid_from_name($username); } } } $user_id_list = array_unique($user_id_list); } } if (isset($error)) { $template->set_filenames(array( 'reg_header' => 'error_body.tpl') ); $template->assign_vars(array( 'ERROR_MESSAGE' => $error_msg) ); $template->assign_var_from_handle('ERROR_BOX', 'reg_header'); } else { $amount = abs(intval($HTTP_POST_VARS['amount'])); $method_function = ($HTTP_POST_VARS['method']) ? 'add_points' : 'subtract_points'; foreach ($user_id_list as $user_id) { if (!empty($user_id)) { $method_function($user_id, $amount); } } $loc = (isset($HTTP_POST_VARS['location']) && !empty($HTTP_POST_VARS['location'])) ? $HTTP_POST_VARS['location'] : append_sid("pointscp.$phpEx?mode=donate"); $template->assign_vars(array( 'META' => '<meta http-equiv="refresh" content="3;url=' . $loc . '">') ); $msg = sprintf($lang['Points_user_updated'], $board_config['points_name']) . '<br /><br />' . sprintf($lang['Click_return_pointscp'], '<a href="' . append_sid("pointscp.$phpEx") . '">', '</a> ') . '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a>'); message_die(GENERAL_MESSAGE, $msg); } } $s_username = (!empty($user_id)) ? get_username_from_id($user_id) : ''; $location = (!isset($HTTP_POST_VARS['location'])) ? $HTTP_SERVER_VARS['HTTP_REFERER'] : $location; $s_hidden_fields = '<input type="hidden" name="location" value="' . $location . '">'; $template->assign_vars(array( 'L_FIND_USERNAME' => $lang['Find_username'], 'L_ADD' => $lang['Add'], 'L_SUBTRACT' => $lang['Subtract'], 'L_SUBMIT' => $lang['Submit'], 'L_RESET' => $lang['Reset'], 'L_POINTS_TITLE' => $lang['Points_cp'], 'L_AMOUNT' => $lang['Points_amount'], 'L_AMOUNT_GIVE_TAKE' => sprintf($lang['Points_give_take'], $board_config['points_name']), 'L_METHOD' => $lang['Points_method'], 'L_ADD_SUBTRACT' => sprintf($lang['Points_add_subtract'], $board_config['points_name']), 'L_MASS_EDIT' => $lang['Points_mass_edit'], 'L_MASS_EDIT_EXPLAIN' => $lang['Points_mass_edit_explain'], 'USERNAME' => $s_username, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_POST_ACTION' => append_sid("pointscp.$phpEx", true), 'U_SEARCH_USER' => append_sid("search.$phpEx?mode=searchuser")) ); $template->assign_block_vars('switch_points_cp', array());}//// Start output of page//$page_title = $lang['Points_sys'];include($phpbb_root_path . 'includes/page_header.'.$phpEx);//// Generate the page//$template->pparse('body');include($phpbb_root_path . 'includes/page_tail.'.$phpEx);?>[/code] Link to comment https://forums.phpfreaks.com/topic/20555-points-system-help/ Share on other sites More sharing options...
vigiw Posted September 12, 2006 Author Share Posted September 12, 2006 *bump* Link to comment https://forums.phpfreaks.com/topic/20555-points-system-help/#findComment-90712 Share on other sites More sharing options...
gijew Posted September 12, 2006 Share Posted September 12, 2006 No offense but I'm not reading through all of that code.Just look up a tutorial on how to create forms with php. Check the database to see if they have any points, if they don't tell them they need points. If they have points, see if it matches the purchase amount. It's like 2 queries, really. You should be able to do it yourself with little time invested without having to write a huge application. Link to comment https://forums.phpfreaks.com/topic/20555-points-system-help/#findComment-90734 Share on other sites More sharing options...
vigiw Posted September 12, 2006 Author Share Posted September 12, 2006 I know how to write the PHP form, I do not know exactly how to incorporate the MySQL. I have working PHP forms writing new information to empty tables in MySQL, but nothing of this nature. I understand, but that file was just to get an idea what I am talking about because it does what I need to do.I already have the database set-up and working, has been for months with real data on it, like I said. The table containing user data, including points data is called phpbb_users and the "field"(name?) is called user_pointsAny ideas how I can make the form do the following according to selection or whatever the user is "buying":Subtract x amount of points from y (current amount of points) stored in the database, making sure the user has enough, everything is correct, etc.?Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/20555-points-system-help/#findComment-90755 Share on other sites More sharing options...
gijew Posted September 12, 2006 Share Posted September 12, 2006 I'll give you a couple of sample queries and tell you about how I might do it = )First, take the points of the product they are trying to buy and store it in a variable.$Product = 'pointValueX';Second, check the amount of points they have available.$sqlCheckPoints = mysql_fetch_array("SELECT points FROM table WHERE user_id = $UserID");$availablePoints = $sqlCheckPoints['points'];After you have those two, you could write your conditionals to test if they have the available points there. Just subtract the two amounts to get your new amount and update the database.$newPointCount = $availablePoints - $Product;$updateTable = mysql_query("UPDATE table SET points = $newPointCount WHERE user_id = $userID");That's about how I may approach that one = ) Link to comment https://forums.phpfreaks.com/topic/20555-points-system-help/#findComment-90758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.