My script is outputting a blank page. Any ideas why?

I am just learning php coding and I have made a bank script for a small online game I am trying to create.
Before I added the if and else to the code to limit a user from depositing or withdrawing more money than they had. The Submit button would either add money to the users account, minus a 2% deposit fee. Or the user could withdraw money from their account with no penalties. Now all that happens is the page comes up blank.
Here is my main bank page code.
[php] <?php
include(“safe.php”);
?>
Would you like to Deposit or Withdraw some money.

The deposit fee is 2%.

The bank has no penalty for a withdraw.
You have $<?php echo $stats['bank']; ?> in the bank right now.
You have $<?php echo $stats['gold']; ?> in your pocket right now.
<form name="input" action="bank_action.php" method="post">

Amount to Deposit

Amount to Withdraw [/php]

This is the page I think the problem is occurring in.
[php]<?php
include(“safe.php”);
if(!isset($_POST[‘withdraw’])){
$withdraw = $_POST[‘withdraw’];
$total1 = $withdraw;
$round1 = floor($total1);
if($total1 > $stats[‘bank’]);{
echo(“You don’t have that much money in the bank! Go back and try entering a real number!”);
}if($total1 < $stats[‘bank’]);
$pocket1 = mysql_query(“UPDATE stats SET gold=gold+’”.$total1."’ WHERE id=’$_SESSION[uid]’") or die(mysql_error());
$bank1 = mysql_query(“UPDATE stats SET bank=bank-’”.$total1."’ WHERE id=’$_SESSION[uid]’") or die(mysql_error());
header(“Location: bank_succ.php”);
}
else{
if(!isset($_POST[‘deposit’])){
$deposit = $_POST[‘deposit’];
$percent = 2;
$total = $deposit;
$tmppercent=100-$percent;
$equals=($total / 100 * $tmppercent);
$round = ceil($equals) ;
$depos = ($total - $round);
if($total < $stats[‘gold’]);{
echo(“You don’t have that much money in your pocket! Go back and try entering a real number!”);
}if(total > $stats[‘gold’]);
$pocket = mysql_query(“UPDATE stats SET gold=gold-’”.$total."’ WHERE id=’$_SESSION[uid]’") or die(mysql_error());
$bank = mysql_query(“UPDATE stats SET bank=bank+’”.$round."’ WHERE id=’$_SESSION[uid]’") or die(mysql_error());
header(“Location: bank_succ.php”);
}
}

?>[/php]

And the last page that is in the program is the success page.

[php] <?php
echo “You now have $”.$stats[‘gold’]." in your pocket right now.
“;
echo “You now have $”.$stats[‘bank’].” in your account now."
?> [/php]

I am hoping it is something simple. Any ideas or even a link to a page that might give me a clue. I have been trying to get this portion resolved for a few days now. Any help would be appreciated.

hello Bashere,
you doing missing to put semi-colon that’s why you are getting blank page.
use this line.
echo “You now have $”.$stats[‘bank’]." in your account now.";

SR

I added the ; to the code. For some reason it is not going to the succeed page. Its posting the code page with nothing in it, no redirect.

hello Bashere,
this time your are missing $ symbol before total in your if statement.

remove this code

if(total > $stats[‘gold’]);
use this code
if($total > $stats[‘gold’]);

SR

Yeah I tried it again. Still no go… This has been giving me fit for a few days.

hello Bashere,
i am not getting you.
Can you explain?

regarding you issue it must be $total instead of total in if condition
SR

I am not getting any errors. With the code above, when I enter a number and click submit. Nothing happens, before I added the if and else to the code everything worked, the redirect to the bank_succ.php worked fine and showed if you deposited and withdrew money.
Now I just get a blank page of bank_action.php. Hope this helps.

hello Bashere,
thanks for explaination.
here is the issue in you code. it’s related with syntax
use below php code
[php]

<?php include("safe.php"); if(!isset($_POST['withdraw'])) { $withdraw = $_POST['withdraw']; $total1 = $withdraw; $round1 = floor($total1); if($total1 > $stats['bank']) { echo("You don't have that much money in the bank! Go back and try entering a real number!"); } if($total1 < $stats['bank']) { $pocket1 = mysql_query("UPDATE `stats` SET `gold`=`gold`+'".$total1."' WHERE id='$_SESSION[uid]'") or die(mysql_error()); $bank1 = mysql_query("UPDATE `stats` SET `bank`=`bank`-'".$total1."' WHERE id='$_SESSION[uid]'") or die(mysql_error()); header("Location: bank_succ.php"); } } else { if(!isset($_POST['deposit'])) { $deposit = $_POST['deposit']; $percent = 2; $total = $deposit; $tmppercent=100-$percent; $equals=($total / 100 * $tmppercent); $round = ceil($equals) ; $depos = ($total - $round); if($total < $stats['gold']){ echo("You don't have that much money in your pocket! Go back and try entering a real number!"); } if(total > $stats['gold']) { $pocket = mysql_query("UPDATE `stats` SET `gold`=`gold`-'".$total."' WHERE id='$_SESSION[uid]'") or die(mysql_error()); $bank = mysql_query("UPDATE `stats` SET `bank`=`bank`+'".$round."' WHERE id='$_SESSION[uid]'") or die(mysql_error()); header("Location: bank_succ.php"); } } } ?>

[/php]

SR

Nope, I just tried the code both ways.
[php]if(total > $stats[‘gold’])[/php]
and
[php]if($total > $stats[‘gold’])[/php]
I tried the code as you pasted and with the above correction.
I get the same thing. Nothing. :frowning:

I wouldn’t mind using my old code, but that would rely on the honesty of the players to withdraw and deposit money in the correct amounts, but you and I both know that would not happen…

hello Bashere,
i think you are $stats[‘bank’] or $stats[‘gold’] is blank.
please check this two things first.
SR

All users $stats['gold']
have money in hand. Just recently added the $stats['gold']

So not sure why it would matter if they were blank. the bank will be blank till a deposit is made. I was hoping that the code for adding more money than you had on hand would do just that, not let the user go into a negative number when they deposit 10,000 into the bank and they have -10,000 in their hand.

So, you really want to try to do some math inside a query??? Bad programming style!
You should do the calculation in your PHP and then just do the update to the results…
So, for this part of the query: SET bank=bank-’".$total1."’ as an example…
You should do the math first: $newbank = $bank - $total1;
and then do the UPDATE…

What I am saying is that you shouldn’t do the math in the query. Most likely there are issues in those two lines where you add amounts and subtract amounts. Do the math in your PHP code and just UPDATE the values.
If you really need to do the math inside the queries, make sure they are set up correctly. I would suggest echo’ing the two queries and try them in your MySQL’s admin program to see if they are valid. Most likely they are not… Hope that helps…

Thanks for the input. As i stated earlier i am new to programming. I have tried almost everything i could research online before i came to the site for some help. I will give it a go in the morning after i sleep on it for a few hours.
I will update here as to what the outcome is.

Okay, and if you want us to help further, just show a few more lines of the update section.
I think you are close to it, just do the actual computations before doing the update and in the
update query, use the calculated totals to update. It should work… We will look tomorrow for
your tests or further questions… Good luck!

Ok i finally got it sorted out. I had a few small problems figured out( trial and error). I had to change my first page as the submit button was taking me to a old page.
Secondly i split up the withdraw pages and deposit pages, as i could never successfully get them to work right with the if and else statements. Here are my final 2 pages to make it work for a reference. The only thing i lack now it a round portion. I don’t want to have to deal with cents only dollars.
[php]<?php
include(“safe.php”);
if(!isset($_POST[“deposit”]))
$percent = (($_POST[“deposit”]) * .02);
$totalPrice = ($_POST[“deposit”]);
$discountPrice = ($totalPrice - ($totalPrice * 0.02));
if(($_POST[“deposit”]) <= $stats[‘gold’]){
$gold1 = mysql_query(“UPDATE stats SET gold=gold - '”.$totalPrice."’ WHERE id=’$_SESSION[uid]’") or die(mysql_error());
$bank1 = mysql_query(“UPDATE stats SET bank=bank + '”.$discountPrice."’ WHERE id=’$_SESSION[uid]’") or die(mysql_error());
header(“Location: bank_succ.php”);
}
elseif(($_POST[“deposit”]) > $stats[‘gold’])
echo “You don’t have the much money in your account. Go back and enter a real number!”;

?>[/php]

now the withdraw page.
[php]<?php
include(“safe.php”);
if(!isset($_POST[“withdraw”]))
$withdraw = $_POST[“withdraw”];
if(($_POST[“withdraw”]) <= $stats[‘bank’]){
$gold1 = mysql_query(“UPDATE stats SET gold=gold + '”.($_POST[“withdraw”])."’ WHERE id=’$_SESSION[uid]’") or die(mysql_error());
$bank1 = mysql_query(“UPDATE stats SET bank=bank - '”.($_POST[“withdraw”])."’ WHERE id=’$_SESSION[uid]’") or die(mysql_error());
header(“Location: bank_succ.php”);
}
elseif(($_POST[“withdraw”]) > $stats[‘bank’])
echo “You don’t have the much money in your account. Go back and enter a real number!”;
?>[/php]

Thanks for the help

Rounding is easy. PHP has a nice function for that. Here is details on it. Hope that helps…

http://php.net/manual/en/function.round.php

Sponsor our Newsletter | Privacy Policy | Terms of Service