Jump to content
MakeWebGames

A little help


newttster

Recommended Posts

I am trying to get a mod that I am working on to work ... and it does ... sort of. The code that I am posting is part and parcel of a much larger mod, however, if I can't get this to work the rest won't. I don't get any error messages. In the function do_open-ba ... it is not switching the status of the account from closed to open. On my users table I have it set up as enum with closed being the default. Any suggestions as to how I can fix this?

<?php
include "globals.php";
switch ($_GET['action'])
{
case "openba":
conf_open_ba();
break;

case 'openba2':
do_open_ba();
break;

case 'babanking':
conf_ba_banking();
break;

case 'depositba':
deposit_ba();
break;

case 'withdrawba':
withdraw_ba();
break;

case 'acctsopen':
accts_open();
break;

default:
banking_home();
break;
}
#-----------------------------------------------------#
#----this is the defalt function--------#
function banking_home()
{
global $db,$ir,$c,$userid,$h;
echo "<h3>Financial Trust</h3><br /><br />
<a href='banking.php?action=openba'>Open a Starter Bank Account today</a><br />
If you already have any accounts that are open and wish to use them, 
<a href='banking.php?action=acctsopen'>ENTER HERE<a/<br /><br />
<a href='explore.php'>Changed your mind? Go back to town.</a><br />";
}
#----this function confirms if they want to open an account------#
function conf_open_ba()
{
global $db,$ir,$c,$userid,$h;
if($ir['stacct']=="closed")
{
echo "Are you sure you want to open a Starter Bank Account today?<br />
<a href='banking.php?action=openba2'>Yes</a> OR 
<a href='banking.php'>No</a>";
}
else
{
echo "You already have a Starter Bank Account. Why are you trying to open another one?<br />
<a href='banking.php'>Back to the bank.</a><br />
<a href='explore.php'>Back to town.</a><br />";
}
}
#----this function confirms opening the account------#
function do_open_ba()
{
global $db,$ir,$c,$userid,$h;
if ($ir['money']>9999)
{
echo "Congratulations! You've opened a Starter Bank Account for \$10,000.00.<br />
You will earn 1% on your balance daily. If you have a SBA Investment Certificate you will earn 4%.<br />
If you have <b>more than</b> \$10,000,000.00 in your account you will <b>not</b> earn any interest.<br />
<a href='banking.php?action=babanking'>Begin using my account now.</a><br />";
$db->query("UPDATE users SET stacct='open' WHERE userid=$userid");
$db->query("UPDATE users SET money=money-10000, cybermoneyba=0 WHERE userid=$userid");
}
else
{
echo "You don't have enough money available to open a Starter Bank Account at this time.<br />
<a href='banking.php'>Back to the bank</a><br /> 
<a href='explore.php'>Back to town</a><br />";
}
}
#----this function determines whether they want to deposit or withdraw------#
function conf_ba_banking()
{
global $db,$ir,$c,$userid,$h;
echo "What would you like to do today?<br />
<a href='banking.php?action=depositba'>Deposit</a></br />
<a href='banking.php?action=withdrawba'>Withdraw</a><br />";
}
#---deposit function-------#
function deposit_ba()
{
global $db,$ir,$c,$userid,$h;
$_POST['depositba']=abs((int)$_POST['depositba']);
if($_POST['depositba']>$ir['money'])
{
echo "You don't have enough money to deposit this amount.<br />
<a href='banking.php'>Back to the bank</a><br />
<a href='explore.php'>Back to town</a><br />";
}
if($ir['stacct']='closed')
{
echo "You have not opened a Starter Bank Account yet.<br />
<a href='banking.php'>Back to the bank</a><br />
<a href='explore.php'>Back to town</a><br />";
}
else
{
echo "You currently have \${$ir['cybermoneyba']} in your Starter Bank Account.<br />
<table width='75%' cellspacing=1 class='table'>
<tr><td width='50%'>Deposit Money<br />
<form action='banking.php?action=depositba' method='POST'>
Amount:
<input type='text' name='depositba' value='{$ir['money']}/><br />
<input type='submit' value='Deposit'/>
</form></td></tr></table><br />";
$gain=$_POST['depositba'];
$db->query ("UPDATE users SET cybermoneyba = cybermoneyba+$gain, money=money-{$_POST['depositba']} WHERE userid=$userid");
echo "You give the teller \${$_POST['depositba']}.<br />
You now have \${$ir['cybermoneyba']} in your Starter Bank Account.<br />
<a href='banking.php'>Continue banking.</a><br />
<a href='explore.php'>Go back to town.</a><br />";
}
}
#----withdraw function------#
function withdraw_ba()
{
global $db,$ir,$c,$userid,$h;
$_POST['witdhrawba']=abs((int)$_POST['withdrawba']);
if(($_POST['withdrawba'])>$ir['cybermoneyba'])
{
echo "You don't have enough money in your Starter Bank Account to withdraw this amount.<br />
<a href='banking.php'>Back to the bank</a><br />
<a href='explore.php'>Back to town</a><br />";
}
if ($ir['stacct']='closed')
{
echo "You can't withdraw money from an account that you have not opened yet.<br />
<a href='banking.php'>Back to the bank</a><br />
<a href='explore.php'>Back to town</a><br />";
}
else
{
echo "You currently have \${$ir['cybermoneyba']} in your Starter Bank Account.<br />
<table width='75%' cellspacing=1 class='table'>
<tr><td width='50%'>Withdraw Money<br />
<form action='banking.php?action=withdrawba' method='POST'>
Amount:
<input type='text' name='withdrawba' value='{$ir['cybermoneyba']}/><br />
<input type='submit' value='Withdraw'/>
</form></td></tr></table><br />";
$gain=$_POST['withdrawba'];
$db->query ("UPDATE users SET cybermoneyba = cybermoneyba-$gain, money=money+{$_POST['withdrawba']} WHERE userid=$userid");
echo "The teller gives you \${$_POST['withdrawba']}.<br />
You now have \${$ir['cybermoneyba']} left in your Starter Bank Account.<br />
<a href='banking.php'>Continue banking.</a><br />
<a href='explore.php'>Go back to town.</a><br />";
}
}
#-------if they already have accounts open this brings them to the deposit/withdraw functions----#

function accts_open()
{
global $db,$ir,$c,$userid,$h;
echo "<h3>What would you like to do with your accounts today?<h3></br>
<a href='banking.php?action=depositba'>Deposit money to you Starter Bank Account.</a><br />
<a href='banking.php?action=withdrawba'>Withdraw money to you Starter Bank Account.</a><br />
}
$h->endpage();
?>
Link to comment
Share on other sites

@gupreet ... I have tried the two options that you have suggested as well. Neither worked. Though I do thank you for that.

@SomeRandomBastard ... okay ... it does change stacct to open once I run the query through phpmyadmin. I also verified on my users table that the enum () is lower case.

Link to comment
Share on other sites

That worked perfectly ... it now sets the account to open and cybermoneyba to 0. Which is fantastic. Thank you so much.

Now I am getting another issue. *facepalms*

When I try and use the deposit/withdraw function it tells me "You can't deposit/withdraw money from an account that you have not opened yet."

Link to comment
Share on other sites

That worked perfectly as well. Thank you once again.

It deposits the money correctly. It also withdraws the money correctly ... but I am getting the below error message on the withdraw_ba function. Which is weird considering the function does what it is supposed to do.

QUERY ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' money=money+ WHERE userid=42' at line 1

Query was UPDATE users SET cybermoneyba = cybermoneyba-, money=money+ WHERE userid=42

Link to comment
Share on other sites

Thank you so much for all of your help on this. It is all working fantastically now.

Can you explain to me why it is depositing or withdrawing more than what it should? For example if I have $10,000 ($ir['money']) out I can enter $110,000 ($ir['cybermoneyba']) and it will deposit that amount to the Starter Account leaving me with a $100,000 ($ir['money'])deficit in the cash on hand. It does the same with the withdraw as well. I can have $50,000 ($ir['cybermoneyba']) and yet I can withdraw $100,000 from the cyber account leaving me with a deficit of $50,000 in the Starter Account.

In the code I have it set up with the if statement ... if($_POST['depositba']>($ir['money'])) ... and the error message and it does post the error message. Obviously I am missing something here ... but I don't know what it is. Any ideas?

Link to comment
Share on other sites

Thank you, Lithium ... that did it.

Thank you everyone for your help with this. Once I have the whole mod worked out ... I will be putting it up as a free one as a payback for the help. I know for the ones who helped me, it won't be worth much to you but I believe in paying forward ... so thanks again.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...