Jump to content

Archived

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

R1der

Whats wrong with this code?

Recommended Posts

[code]<?
if(!$_GET['stp']){
?>
<b>Welcome to the gem exchange.<br>

<a href="gexchange.php?stp=ene">Exchange 5 gems for 100 energy</a><br>

<?
}
elseif($_GET['stp']==ene){
if($user['uGems']== "<4"){
echo "You Dont have enough gems for this exchange.";
exit;}
else{
echo "You exchanged 5 gems into 100 energy";

$db->query("UPDATE users SET uAttackTurns=uAttackTurns+'100' , uGems=uGems-'5' WHERE uID='" . $user['uID'] . "'");

}
}

?>[/code]

Basicly the exchange does fine but it dont stop them from exchanging gems even when thay go into minus.

can anyone help with this problem?

Thanks in advance.

Share this post


Link to post
Share on other sites
Your syntax is slightly wrong, try this...

[code]<?php
if(!$_GET['stp']){
?>
<b>Welcome to the gem exchange.<br>

<a href="gexchange.php?stp=ene">Exchange 5 gems for 100 energy</a><br>

<?php
}
elseif($_GET['stp'] == "ene"){
if($user['uGems'] <= 4){
echo "You Dont have enough gems for this exchange.";
exit;}
else{
echo "You exchanged 5 gems into 100 energy";

$db->query("UPDATE users SET uAttackTurns=uAttackTurns+'100' , uGems=uGems-'5' WHERE uID='" . $user['uID'] . "'");

}
}
?>[/code]

When checking a string, use double quotes, so [code=php:0]if $var == "string"[/code] you had no quotes

When comparing numbers, no need for the quotes so [code=php:0]if $var <= 4[/code] you had the 4 in quotes along with the less than sign.

Regards
Huggie

Share this post


Link to post
Share on other sites

×

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.