Error msgs showing before it should

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Error msgs showing before it should

Post 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
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Error msgs showing before it should

Post 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.
Post Reply