function set_global_var($var, $data) { global $session; global $specialinc; $query = "SELECT * FROM globalvars WHERE variable='{$var}'"; $res = db_query($query) or die(db_error($link)); if (db_num_rows($res)) { $query = "UPDATE globalvars SET data='{$data}' WHERE variable='{$var}'"; } else { $query = "INSERT INTO globalvars (variable, data)\n VALUES ('{$var}', '{$data}') "; } if ($data === NULL) { $query = "DELETE FROM globalvars WHERE variable='{$var}'"; } $res = db_query($query) or die(db_error($link)); $retval = get_global_var($var); return $retval; }
<?php /*************************************************************************** // Gem Exchange v1.0 // Coded by: Turock // Allows players to exchange gems for gold ***************************************************************************/ require_once "common.php"; // exchange rate for gems $ex_rate = get_global_var(ExchangeRate); page_header("Gem Exchange"); addnav("Sell your Gems", "gemshop.php?op=sell"); addnav("Return to the Village", "village.php"); $gemsell = $session['user']['gems']; output("`n`^You enter the shop and see an old man sitting behind a small counter.`n"); output("He doesn't say anything and instead points to a small sign...`n"); output("`nThe sign reads: `%Gem Exchange Rate Today: `&1 `^gem = `%" . commas($ex_rate) . " `^gold"); if ($HTTP_GET_VARS['op'] == "sell") { if ($session['user']['gems'] < 1) { output("`n`nYou don't have any gems to sell.`n"); } else { $word = "gems"; if ($session['user']['gems'] == 1) { $word = "gem"; } output("`n`n`^You have `&{$gemsell} `^{$word} to sell.`n"); output("`%How many would you like to sell?`n"); output("<form action='gemshop.php?op=sell2' method='POST'><input name='sell' id='sell'><input type='submit' class='button' value='sell'></form>", true); addnav("", "gemshop.php?op=sell2"); } }