Jump to content

Whats wrong with this code?


R1der

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.
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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