xwishmasterx Posted April 25, 2011 Share Posted April 25, 2011 I have a this piece of code, and simply need to make the last piece work: $amount = $_POST['amount']; ......... $query = mysql_query("SELECT * FROM teams WHERE team_id='$te' ") or die(mysql_error()); $result = mysql_fetch_array( $query ); if($result['team_treasure'] <= '$amount'){ echo "<br><br><div align='center'>Transfer Failed: Not enough credits</div> ";} else { echo "<br><br><div align='center'>Transfer Completed!</div>";} It returns Transfer Completed!, no matter if team_treasure is higher or lower than $amount Quote Link to comment https://forums.phpfreaks.com/topic/234711-adding-some-ifs-at-end-of-script/ Share on other sites More sharing options...
Fadion Posted April 25, 2011 Share Posted April 25, 2011 Remove single quotes in the variable, or you'll treat it as string. Replace if($result['team_treasure'] <= '$amount'){ with: if($result['team_treasure'] <= $amount){ Quote Link to comment https://forums.phpfreaks.com/topic/234711-adding-some-ifs-at-end-of-script/#findComment-1206139 Share on other sites More sharing options...
Psycho Posted April 25, 2011 Share Posted April 25, 2011 Then echo the data to the page to validate your hypothesis. And, as GuiltyGear stated - compare it as a number, not a string $amount = $_POST['amount']; //......... //Only query the field you need $query = mysql_query("SELECT `team_treasure` FROM teams WHERE team_id='$te' ") or die(mysql_error()); $result = mysql_fetch_assoc($query); //Add a debug line: echo "Result['team_treasure']:{$result['team_treasure']}, Amount:{$amount}<br>\n"; if($result['team_treasure'] <= '$amount') { echo "<br><br><div align='center'>Transfer Failed: Not enough credits</div> "; } else { echo "<br><br><div align='center'>Transfer Completed!</div>"; } Quote Link to comment https://forums.phpfreaks.com/topic/234711-adding-some-ifs-at-end-of-script/#findComment-1206141 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.