dimanche 28 juin 2015

Something wrong with my IF statement

I created a simple code for my web game, there are no errors but some part of the code does not work. Parts which do not work are last two if statements, it won't give users an Antimatter, but it prints out correct message. Why it won't update DB correctly ?

CODE:

    ///////////////////////////////BLACKBOX////////////////
function buyblackbox(){
global $USER, $PLANET, $LNG, $UNI, $CONF,$resource,$pricelist;
$blackbox = HTTP::_GP('blackbox', 0);
$price = 10000 * $blackbox;
$loli   = mt_rand(1,2);
if ($price < 0) {
$this->printMessage("Hack attempt.", true, array('game.php?page=premium', 2));
}
if($USER['antimatter'] < $price){
$this->printMessage("You do not have enough antimatter", true, array('game.php?page=premium', 2));
die();
}
elseif($blackbox < 0){
$this->printMessage("Hack attempt.", true, array('game.php?page=premium', 2));
die();
}else{
    $USER['antimatter'] -= $price;
$GLOBALS['DATABASE']->query("UPDATE ".USERS." SET `darkbox` = '".$loli."', `antimatter` = `antimatter` - '".$price."' WHERE `id` = ".$USER['id'].";");

if($USER['darkbox'] == 1)
{
$GLOBALS['DATABASE']->query("UPDATE ".USERS." SET `darkmatter` = `darkmatter` - '".$price."' WHERE `id` = ".$USER['id'].";");
$this->printMessage('vins nem sit has succesfully be bought', true, array('game.php?page=premium', 2));
}
if($USER['darkbox'] == 2)
{
$GLOBALS['DATABASE']->query("UPDATE ".USERS." SET `darkmatter` = `darkmatter` + '".$price."' WHERE `id` = ".$USER['id'].";");
$this->printMessage('BlackBox has succesfully be bought', true, array('game.php?page=premium', 2));
}
}
die();
}
/////////////////////////////////END BLACKBOX///////////////////////

Aucun commentaire:

Enregistrer un commentaire