Jump to content

Comparing Strings


AirBoss36

Recommended Posts

I want to compare two strings for an if statement.  With something like a bank account, I want it to check and see if there is enough money in the account before it performs the transaction.  Here is what I've tried:

$balance = 100;
$trans = 200;

if (($trans < $balance) || ($trans == $balance)) {

    ***perform transaction***
}

?>

<html>..... Msg stating not enough money in the account.

In the scenario, it should not perform the transaction, and then should carry on to the html to say that there is not enough money in the account.  At least, that's what i want it to do. 

Right now, it processes the transaction even though its greater than the balance.  What am I doing wrong?

Thanks.
Link to comment
Share on other sites

That code is fine, although you could write it like this:
[code]<?php
$balance = 100;
$trans = 200;

if ($trans <= $balance)  {

    ***perform transaction***
}

?>[/code]

For us to figure out your problem, we would need more information.

Ken
Link to comment
Share on other sites

If I'm using the statement correctly, why would it process the transaction if the balance is less than the transaction?

Should I attack from the other direction?

if ($trans > $balance) {

echo "Not enough money";

exit();

}

else {

*** process transaction***
}
?>
Link to comment
Share on other sites

[quote author=AirBoss36 link=topic=105921.msg423269#msg423269 date=1156765653]
If I'm using the statement correctly, why would it process the transaction if the balance is less than the transaction?

Should I attack from the other direction?

if ($trans > $balance) {

echo "Not enough money";

exit();

}

else {

*** process transaction***
}
?>
[/quote]

yes, you should be attacking it from this new direction. basically, you want to say that if the transaction is [b]more[/b] than their balance, you don't want to let them do it:
[code]
<?php
if ($trans > $bal) {
  // too much, don't process
} else {
  // valid request, process it
}
?>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.