IFs and $_REQUESTs not working?
Posted: Thu Apr 07, 2005 8:31 pm
I can't figure out what's wrong with this. I've been looking at it for a couple hours, but nothing I try fixes it. If I go to game.php?do=sell then nothing happens. Nothing except what happens everytime you go to the page, which is not included in this.
Code: Select all
<?php
if($_REQUEST['do'] == "buy") {
$buy = $_REQUEST['buy'];
if($_REQUEST['what'] == "weapon") {
$gold = mysql_query("SELECT gold FROM users WHERE userid='$userid'");
$gold = mysql_fetch_array($gold);
$gold = $gold[0];
$weapon = mysql_query("SELECT weapon FROM users WHERE userid='$userid'");
$weapon = mysql_fetch_array($weapon);
$weapon = $weapon[0];
if($weapon > 0) {
print("You already have a weapon! You need to sell it before buying another one!");
} else {
$wep = mysql_query("SELECT * FROM weapons WHERE `id`='$buy'");
$wep = mysql_fetch_assoc($wep);
if($gold >= $wep['price']) {
mysql_query("UPDATE users SET gold=(gold - {$wep['price']}) WHERE userid='$userid'");
mysql_query("UPDATE users SET weapon='$buy' WHERE userid='$userid'");
echo "You bought the " . $wep['name'];
} else {
echo "You don't have enough gold to buy that!";
}
}
} elseif($_REQUEST['what'] == "armor") {
$gold = mysql_query("SELECT gold FROM users WHERE userid='$userid'");
$gold = mysql_fetch_array($gold);
$gold = $gold[0];
$armor = mysql_query("SELECT armor FROM users WHERE userid='$userid'");
$armor = mysql_fetch_array($armor);
$armor = $armor[0];
if($armor > 0) {
print("You already have an armor! You need to sell it before buying another one!");
} else {
$arm = mysql_query("SELECT * FROM armor WHERE `id`='$buy'");
$arm = mysql_fetch_assoc($arm);
if($gold >= $arm['price']) {
mysql_query("UPDATE users SET gold=(gold - {$arm['price']}) WHERE userid='$userid'");
mysql_query("UPDATE users SET armor='$buy' WHERE userid='$userid'");
echo "You bought the " . $arm['name'];
} else { echo "You don't have enough gold to buy that!"; }
}
if($_REQUEST['do'] == "sell") {
echo "test";
if($_REQUEST['what'] == "weapon") {
$weapon = mysql_query("SELECT weapon FROM users WHERE userid='$userid'");
$weapon = mysql_fetch_array($weapon);
$weapon = $weapon[0];
$gold = mysql_query("SELECT gold FROM users WHERE userid='$userid'");
$gold = mysql_fetch_array($gold);
$gold = $gold[0];
if($weapon == $_REQUEST['sell']) {
$weapon = mysql_query("SELECT weapon FROM users WHERE userid='$userid'");
$weapon = mysql_fetch_array($weapon);
$weapon = $weapon[0];
$update = mysql_query("UPDATE users SET weapon = '0' WHERE userid='$userid'");
$sellfor = mysql_query("SELECT price FROM weapons WHERE id='$weapon'");
$sellfor = mysql_fetch_array($sellfor);
$sellfor = $sellfor[0] / 2;
$query = mysql_query("UPDATE users SET gold=(gold + $sellfor) WHERE userid='$userid'");
print("You have sold your weapon for $sellfor g.");
} else {
print("You don't have a weapon to sell!");
}
}
if($_REQUEST['what'] == "armor") {
$armor = mysql_query("SELECT armor FROM users WHERE userid='$userid'");
$armor = mysql_fetch_array($armor);
$armor = $armor[0];
mysql_query("UPDATE users SET armor='0' WHERE userid='$userid'");
$sellfor = mysql_query("SELECT price FROM armor WHERE id='$armor'");
$sellfor = mysql_fetch_array($sellfor);
$sellfor = $sellfor[0] / 2;
$query = mysql_query("UPDATE users SET gold=(gold + $sellfor) WHERE userid='$userid'");
print("You have sold your armor for $sellfor g.");
} else {
print("You don't have an armor to sell!");
}
}
}
?>