Jump to content

adding some "if"s at end of script.


xwishmasterx

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/234711-adding-some-ifs-at-end-of-script/
Share on other sites

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>";
}

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.