My friend was creating an investment.php mod for my game and stumbled upon an error which he could not find, thats why I'm posting! 8-) The problem is when you withdraw/deposit it does not calculate anything! Below is what he has made, so if anyone would be kind enough to help solve the problem:
Investment.php
<?php
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$cm=money_formatter($ir['crystals'],'');
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm,$cm,0);
$h->menuarea();
print "Investment Bank";
if($ir['bankmoney']>-1)
{
switch($_GET['action'])
{
case "deposit":
deposit();
break;
case "withdraw":
withdraw();
break;
default:
index();
break;
}
}
else
{
if(isset($_GET['buy']))
{
if($ir['money']>49999)
{
print "Congratulations, you bought a bank account for \$50,000!
[url='investment.php']»[b]Start using my account[/b][/url]";
mysql_query("UPDATE users SET money=money-50000,bankmoney=0 WHERE userid=$userid");
}
else
{
print "You do not have enough money to open an account.
[url='explore.php']»[b]Back[/b][/url]";
}
}
else
{
print "Open a bank account today, just \$50,000!
[url='investment.php?buy']»[b]Yes, sign me up![/b][/url]";
}
}
function index()
{
global $db, $ir,$c,$userid,$h;
echo "";
print "\n[b]You currently have \${$ir['bankmoney']} in the bank.[/b]";
if($ir['wait']>0) {echo "[i]You have [b]{$ir['wait']} days[/b] left before you gain your interest![/i]";}
else {echo "[i]How many days would you like your money to sit?[/i]
-----Select-----
None
3Day 4%
Week 10%
3Week 32%
Month 45%
";}
echo "[b]Deposit Money[/b]
» It will cost 15% of the money you deposit » The max taken out will be $3000
Amount:
[b]Withdraw Money[/b]
» There is no fee on withdrawals.
Amount:
";
}
function deposit()
{
global $db,$ir,$c,$userid,$h;
$_POST['deposit']=abs((int) $_POST['deposit']);
if($_POST['deposit'] > $ir['money'])
{
print "You do not have enough money to deposit this amount.";
}
elseif($long = "select")
{
echo "You need to set how long you want to store the money for interest.";
}
{
$intmoney=ceil($_POST['deposit']);
$fee=ceil($_POST['deposit']*15/100);
$long=$_POST['long'];
if($fee > 3000) {$fee=3000;}
if($long == day3) {$wait = '3'; $interest = '($intmoney*.01)+$intmoney';}
elseif($long == 'week') {$wait = '7';$interest = '($intmoney*.03)+$intmoney';}
elseif($long == 'week3') {$wait = '21';$interest = '($intmoney*.11)+$intmoney';}
else {$wait = '31';$interest = '($intmoney*.15)+$intmoney';}
$gain=$_POST['deposit']-$fee;
$ir['bankmoney']+=$gain;
mysql_query("UPDATE users SET bankmoney=bankmoney+$gain, money=money-{$_POST['deposit']}, wait=wait+$wait WHERE interest=$interest userid=$userid");
print "You hand over \${$_POST['deposit']} to be deposited,
after the fee is taken (\$$fee), \$$gain is added to your account.
[b]You now have \${$ir['bankmoney']} in the bank.[/b]
[url='investment.php']>[b]Back[/b][/url]";
}
}
function withdraw()
{
global $db,$ir,$c,$userid,$h;
$_POST['withdraw']=abs((int) $_POST['withdraw']);
if($_POST['withdraw'] > $ir['bankmoney'])
{
print "You do not have enough banked money to withdraw this amount.";
}
if($wait = '-1')
{
$gain=$_POST['withdraw'];
$ir['bankmoney']-=$gain;
$db->query("UPDATE users SET bankmoney=bankmoney-$gain, money=money+$gain where userid=$userid");
print "You ask to withdraw $gain,
the banking lady grudgingly hands it over.
[b]You now have \${$ir['bankmoney']} in the bank.[/b]
[url='investment.php']» Back[/url]";
}
else
{
echo "[b]Banker: You only have [b]{$ir['wait']} days[/b] left before you get interest![/b]";
echo "[i]Are you sure you still want to withdrawl?[/i]";
echo "
";
}
if($_GET['action'] == 'yes')
{
$gain=$_POST['withdraw'];
$ir['bankmoney']-=$gain;
mysql_query("UPDATE users SET bankmoney=bankmoney-$gain, money=money+$gain, wait=-1 where userid=$userid");
print "You ask to withdraw $gain,
the banking lady grudgingly hands it over.
[b]You now have \${$ir['bankmoney']} in the bank.[/b]
[url='investment.php']»[b]Back[/b][/url]";
}
}
$h->endpage();
?>
Daysold.php
<?php
require "mysql.php";
global $c;
mysql_query("UPDATE users SET wait=wait-1 WHERE wait>0");
if($ir['wait'] = 0)
{
mysql_query("UPDATE users SET bankmoney=bankmoney+{$ir['interest']} WHERE bankmoney>0");
mysql_query("UPDATE users SET wait=wait-1 WHERE bankmoney>0");
}
mysql_query("UPDATE users SET daysingang=daysingang+1 WHERE gang > 0",$c);
mysql_query("UPDATE users SET daysold=daysold+1",$c);
mysql_query("UPDATE users SET mailban=mailban-1 WHERE mailban > 0",$c);
mysql_query("UPDATE users SET donatordays=donatordays-1 WHERE donatordays > 0",$c);
mysql_query("UPDATE users SET cdays=cdays-1 WHERE course > 0",$c);
mysql_query("UPDATE users SET bankmoney=bankmoney+(bankmoney/50) where bankmoney>0",$c);
mysql_query("UPDATE users SET cybermoney=cybermoney+(cybermoney/100*7) where cybermoney>0",$c);
$q=mysql_query("SELECT * FROM users WHERE cdays=0 AND course > 0",$c);
while($r=mysql_fetch_array($q))
{
$cd=mysql_query("SELECT * FROM courses WHERE crID={$r['course']}",$c);
$coud=mysql_fetch_array($cd);
$userid=$r['userid'];
mysql_query("INSERT INTO coursesdone VALUES({$r['userid']},{$r['course']})",$c);
$upd="";
$ev="";
if($coud['crSTR'] > 0)
{
$upd.=",us.strength=us.strength+{$coud['crSTR']}";
$ev.=", {$coud['crSTR']} strength";
}
if($coud['crGUARD'] > 0)
{
$upd.=",us.guard=us.guard+{$coud['crGUARD']}";
$ev.=", {$coud['crGUARD']} guard";
}
if($coud['crLABOUR'] > 0)
{
$upd.=",us.labour=us.labour+{$coud['crLABOUR']}";
$ev.=", {$coud['crLABOUR']} labour";
}
if($coud['crAGIL'] > 0)
{
$upd.=",us.agility=us.agility+{$coud['crAGIL']}";
$ev.=", {$coud['crAGIL']} agility";
}
if($coud['crIQ'] > 0)
{
$upd.=",us.IQ=us.IQ+{$coud['crIQ']}";
$ev.=", {$coud['crIQ']} IQ";
}
$ev=substr($ev,1);
if ($upd) {
mysql_query("UPDATE users u LEFT JOIN userstats us ON u.userid=us.userid SET us.userid=us.userid $upd WHERE u.userid=$userid",$c) or die(mysql_error()."
"."UPDATE users u LEFT JOIN userstats us ON u.userid=us.userid SET us.userid=us.userid $upd WHERE u.userid=$userid");
}
mysql_query("INSERT INTO events VALUES('',$userid,unix_timestamp(),0,'Congratulations, you completed the {$coud['crNAME']} and gained $ev!')",$c);
}
mysql_query("UPDATE users SET course=0 WHERE cdays=0",$c);
mysql_query("TRUNCATE TABLE votes;",$c);
?>
Also he added in users table.
interest (int) 11 default 0
wait (int) 11 default -1
Hopefully with that information you can help me/my friend with this problem! Thanks!