Re: [mccode v1] Bank
Here is a the fix for withdraw:
<?php
/*-----------------------------------------------------
-- Forgotten-Lands v1.0 BETA
-- A product of KrAiG
-- Do not send or sell to anyone else
-- Please keep this text here
-----------------------------------------------------*/
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']);
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm);
$h->menuarea();
switch($_GET['action'])
{
case "deposit":
deposit();
break;
case "withdraw":
withdraw();
break;
default:
index();
break;
}
function index()
{
global $ir,$c,$userid,$h;
print "<h2>Bank</h2>
Welcome to the bank, let me check your account, please wait a second...
Ok, you currently have: \${$ir['bankmoney']}.
Your bank type gives you 2% interest a day added to your balance!
<table width='75%' border='2'><tr><td width='50%'>[b]Deposit[/b]
<form action='bank.php?action=deposit' method='post'>
Amount: <input type='text' name='deposit' value='{$ir['money']}' />
<input type='submit' value='Deposit' /></form></td> <td>
[b]Withdraw Money[/b]
<form action='bank.php?action=withdraw' method='post'>
Amount: <input type='text' name='withdraw' value='{$ir['bankmoney']}' />
<input type='submit' value='Withdraw' /></form></td> </tr> </table>";
}
function deposit()
{
global $ir,$c,$userid,$h;
$_POST['deposit']=abs((int) $_POST['deposit']);
if($_POST['deposit'] > $ir['money'])
{
print "You do not have enough to deposit this amount.";
}
else
{
$dep=$_POST['deposit'];
$ir['bankmoney']+=$dep;
mysql_query("UPDATE users SET bankmoney=bankmoney+$dep, money=money-{$_POST['deposit']} where userid=$userid",$c);
print "You slide \${$_POST['deposit']} under the counter.
Bill the banker takes your money and stores it.
He gives you a receipt that reads:
[i]'\$$dep has been added to your account.
You now have \${$ir['bankmoney']} in the bank.
Thankyou for using our service
Your banker for today was Bill Joans'[/i]
[url='bank.php']> Back[/url]";
}
}
function withdraw()
{
global $ir,$c,$userid,$h;
$_POST['withdraw']=abs((int) $_POST['withdraw']);
if($_POST['withdraw'] > $ir['bankmoney'])
{
print "You do not have enough in the bank to withdraw this amount.";
}
else
{
$with=$_POST['withdraw'];
$ir['bankmoney']-=$with;
mysql_query("UPDATE users SET bankmoney=bankmoney-$with, money=money+{$_POST['withdraw']} where userid=$userid",$c);
print "You ask to withdraw \$$with,
Banker Bill took typed on the computer and took out some cash from the till.
He gives you a receipt that reads:
[i]'\$$with has been taken from your account.
You now have \${$ir['bankmoney']} in the bank.
Thankyou for using our service
Your banker for today was Bill Joans'[/i]
[url='bank.php']> Back[/url]";
}
}
$h->endpage();
?>
It works fine for me :)
Gr. Sticky