Page 1 of 1

Error msgs showing before it should

Posted: Wed Nov 11, 2009 9:45 am
by nite4000
Hey everyone I have a page where they must enter an amount no larger then their acct balance. Well I have the code to prevent it from being smaller then the amount allowed to be entered. Now the code that I have to prevent it from being larger then acct balance is what I need help with.

Here is my code for the error msg

$_POST['amount'] is the box they enter numbers in
$cashbal is the available balance

Code: Select all

 
if ($_POST['amount'] <= $cashbal) {
} else {
      $error=TRUE;
  $msg .= '<li>Not enough funds <a href="transfer.php">try again</a></li>';
  }

if someone can help me out I just cant fiqure it out. I have tried both < and > signs and still same thing.


Thanks
Don

Re: Error msgs showing before it should

Posted: Wed Nov 11, 2009 10:49 am
by flying_circus
I'm going on alot of assumptions but your code looks right.

Code: Select all

<?php
  if ($_POST['amount'] <= $cashbal) {
  /** $_POST['amount'] is less than or equal to $cashbal */
    transfer_funds();
  } else {
  /** $_POST['amount'] is greater than $cashbal */
  # Error
    $error=TRUE;
    $msg .= '<li>Not enough funds <a href="transfer.php">try again</a></li>';
  }
?>
There are a few points to consider:
- Are you validating $_POST['amount']? Let's say I visit your webpage and in the amount box I type "a".
- What happens if I transfer a negative amount?
- What if I transfer fractions of a penny?

Obviously, I can't see the rest of your code, but just some food for thought.