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
https://forums.phpfreaks.com/topic/18885-comparing-strings/
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
https://forums.phpfreaks.com/topic/18885-comparing-strings/#findComment-81570
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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