AirBoss36 Posted August 28, 2006 Share Posted August 28, 2006 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. Quote Link to comment Share on other sites More sharing options...
Satria Ox41464b Posted August 28, 2006 Share Posted August 28, 2006 Your example is comparing Integer.and that code should be working like what you expect Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 28, 2006 Share Posted August 28, 2006 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 Quote Link to comment Share on other sites More sharing options...
AirBoss36 Posted August 28, 2006 Author Share Posted August 28, 2006 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 Link to comment Share on other sites More sharing options...
Satria Ox41464b Posted August 28, 2006 Share Posted August 28, 2006 make sure what behind $trans and $balance with:[code]<?php var_dump($trans);var_dump($balance);?>[/code] Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 28, 2006 Share Posted August 28, 2006 [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]<?phpif ($trans > $bal) { // too much, don't process} else { // valid request, process it}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.