Jump to content


Photo

Whats wrong with this code?


  • Please log in to reply
2 replies to this topic

#1 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 11 October 2006 - 03:45 PM

<?
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'] . "'");

}
}

?>

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.

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 11 October 2006 - 03:51 PM

Your syntax is slightly wrong, try this...

<?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'] . "'");

}
}
?>

When checking a string, use double quotes, so
if $var == "string"
you had no quotes

When comparing numbers, no need for the quotes so
if $var <= 4
you had the 4 in quotes along with the less than sign.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 R1der

R1der
  • Members
  • PipPipPip
  • Advanced Member
  • 104 posts

Posted 11 October 2006 - 03:56 PM

Wow that worked great

Thanks




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users