2013-08-27 2 views
-4

Вот мой полный код. Это сработало отлично, когда у меня было все elseif, как будто и все остальное как elseif.Если ElseIf Else ошибка в случайных событиях код

Но мне нужно, чтобы первая инструкция if выполнялась раньше всего. таким образом, если бы у них было меньше минимальных оборотов, они не будут вслух продолжаться. здесь ошибка, я получаю ... Анализировать ошибка: синтаксическая ошибка, неожиданный T_ELSEIF

КОД

<?php 

$ingame = "*"; 
require 'includes/header.php'; 
include 'includes/modzoideditables.php'; 
include 'includes/zoideditables.php'; 
include 'includes/offdefvalues.php'; 
$turns = 5; 
$turns2 = 10; 
$zoidmany = 1; 
$zoidmany2 = 2; 
$excav1 = 1; 
$excav2 = 0; 
$goldgive1 = 500; 
$goldgive2 = 700; 
$goldgive3 = 1000; 
$goldgive4 = 1500; 
$goldgive5 = 2000; 
$fight1 = 20000; 
$fight2 = 27000; 
$fight3 = 31000; 
$goldtake1 = 250; 
$goldtake2 = 500; 
$goldtake3 = 750; 
$goldtake4 = 1000; 
$miner = 5; 

    $rand = rand(1, 22); 
if ($turns > $user['uAttackTurns']) { 
     echo "You don't have enough turns."; 
} 
    $rand = rand(1, 22); 
elseif ($excav1 > $user['uExcavation2']) { 
} 
    else ($rand == 1) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uGatlingzaberfangweap=uGatlingzaberfangweap+$zoidmany,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/>You decide to keep it!</b></center><br /><?php 
    } 
    else ($rand == 2) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uGatlingzaberfangweap=uGatlingzaberfangweap+$zoidmany2,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany2?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/>You decide to keep it!</b></center><br /><?php 

     } 
     elseif ($excav2 = $user['uExcavation2']) { 
} 
    else ($rand == 1) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php 
    ?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php 
    } 
    else ($rand == 2) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany2?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php 
?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php 

    } 
      elseif ($rand == 3) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uWeapon42=uWeapon42+$zoidmany,uAttackTurns=uAttackTurns+'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>You see something shiny in the distance, What is that you wonder?</b></center><br /><?php 
     ?><center><b>You just found a fully working <?=$wp_42_nm?>!<img src="<?=$wp_42_image?>"/></b></center><br /><?php 
     ?><center><b>No need for excavation tools here, This bad boy runs!</b></center><br /><?php 
    } 
     elseif ($fight2 > $defensetotal) { 
} 
    else ($rand == 4) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold+$goldgive3,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a group of <?=$wp_43_nm?>'s <img src="<?=$wp_43_image?>"/>.</b></center><br /> <?php 
     ?><center><b>You managed to fend them off and scored a nice <?=$goldgive3?> gold!</b></center><br /></b></center><br /><?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight2?></b></center><br /></b></center><br /><?php 
    } 
    elseif ($fight2 < $defensetotal) { 
} 
    else ($rand == 4) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold-$goldtake2,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a pack of <?=$wp_43_nm?>'s <img src="<?=$wp_43_image?>"/>.</b></center><br /><?php 
     ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake2?> Gold!</b></center><br /><?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight2?></b></center><br /></b></center><br /><?php 
    } 
      elseif ($fight1 > $defensetotal) { 
} 
    else ($rand == 5) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold+$goldgive2,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a group of <?=$wp_32_nm?>'s <img src="<?=$wp_32_image?>"/>.</b></center><br /> <?php 
     ?><center><b>You managed to fend them off and scored a nice <?=$goldgive2?> gold!</b></center><br /></b></center><br /><?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight1?></b></center><br /></b></center><br /><?php 
    } 
    elseif ($fight1 < $defensetotal) { 
} 
    else ($rand == 5) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold-$goldtake1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a pack of <?=$wp_32_nm?>'s <img src="<?=$wp_32_image?>"/>.</b></center><br /><?php 
     ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake1?> Gold!</b></center><br /><?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight1?></b></center><br /></b></center><br /><?php 
    } 
    elseif ($rand == 6 || $rand == 7) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold-$gold1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just got ambushed. You loose 50 gold!</b></center><br /><?php 
    } 
      elseif ($rand == 8 || $rand == 9 || $rand == 10 || $rand == 11 ) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>After a long hard journey you come up empty handed!</b></center><br /><?php 
    } 
    elseif ($excav1 > $user['uExcavation2']) { 
} 
    else ($rand == 12) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uEleshotbrhinosweap=uEleshotbrhinosweap+$zoidmany,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap6_nm?>. <img src="<?=$mz_weap6_image?>"/>You decide to keep it!</b></center><br /><?php 
    } 
    elseif ($excav2 = $user['uExcavation2']) { 
} 
    else ($rand == 12) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap6_nm?>. <img src="<?=$mz_weap6_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php 
    ?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php 
    } 
     elseif ($fight3 > $defensetotal) { 
} 
    else ($rand == 13) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold+$goldgive4,uWeapon48=uWeapon48+$zoidmany,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a group of <?=$wp_48_nm?>'s <img src="<?=$wp_48_image?>"/>.</b></center><br /> <?php 
     ?><center><b>You managed to fend them off and scored a nice <?=$goldgive4?> gold!</b></center><br /></b></center><br /><?php 
     ?><center><b>You also managed to take a fully working <?=$wp_48_nm?>, <img src="<?=$wp_48_image?>"/>.</b></center><br /> <?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight3?></b></center><br /></b></center><br /><?php 
    } 
    elseif ($fight3 < $defensetotal) { 
} 
    else ($rand == 13) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold-$goldtake3,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a pack of <?=$wp_48_nm?>'s <img src="<?=$wp_48_image?>"/>.</b></center><br /><?php 
     ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake3?> Gold!</b></center><br /><?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight3?></b></center><br /></b></center><br /><?php 
    } 
     elseif ($rand == 14 || $rand == 15 || $rand == 16 || $rand == 17 ) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold+$goldgive1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$goldgive1?> Gold. You decide to keep it!</b></center><br /><?php 
    } 
     elseif ($rand == 18 || $rand == 19 || $rand == 20 || $rand == 21 ) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uMiners=uMiners+$miner,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just found <?=$miner?> miners, your forcing them to join you!</b></center><br /><?php 
    } 
elseif ($turns > $user['uAttackTurns']) { 
} 
    else ($rand == 22) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uAttackTurns=uAttackTurns-$turns,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just lost an additional <?=$turns?>. Better luck next time!</b></center><br /><?php 
    } 

require 'includes/footer.php'; 

?> 

И НИЖЕ рабочий код, единственная проблема у меня есть, КОГДА ОНИ ПРИНИМАЮТ НИЖЕ ПРАВИЛЬНОГО ОГРАНИЧЕНИЯ ОНИ МОГУТ ЕЩЕ ИСПОЛЬЗОВАТЬ ЭТО, ВЫЗЫВАЯ ИХ, ЧТОБЫ ВХОДИТЬ В НЕГАТИВНЫЕ ПОВОРОТЫ.

<?php 

$ingame = "*"; 
require 'includes/header.php'; 
include 'includes/modzoideditables.php'; 
include 'includes/zoideditables.php'; 
include 'includes/offdefvalues.php'; 
$turns = 5; 
$turns2 = 10; 
$zoidmany = 1; 
$zoidmany2 = 2; 
$excav1 = 1; 
$excav2 = 0; 
$goldgive1 = 500; 
$goldgive2 = 700; 
$goldgive3 = 1000; 
$goldgive4 = 1500; 
$goldgive5 = 2000; 
$fight1 = 20000; 
$fight2 = 27000; 
$fight3 = 31000; 
$goldtake1 = 250; 
$goldtake2 = 500; 
$goldtake3 = 750; 
$goldtake4 = 1000; 
$miner = 5; 
    $rand = rand(1, 22); 
if ($turns > $user['uAttackTurns']) { 
     echo "You don't have enough turns."; 
} 
    $rand = rand(1, 22); 
if ($excav1 > $user['uExcavation2']) { 
} 
    elseif ($rand == 1) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uGatlingzaberfangweap=uGatlingzaberfangweap+$zoidmany,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/>You decide to keep it!</b></center><br /><?php 
    } 
    elseif ($rand == 2) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uGatlingzaberfangweap=uGatlingzaberfangweap+$zoidmany2,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany2?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/>You decide to keep it!</b></center><br /><?php 

     } 
     if ($excav2 = $user['uExcavation2']) { 
} 
    elseif ($rand == 1) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php 
    ?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php 
    } 
    elseif ($rand == 2) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany2?> <?=$mz_weap3_nm?>. <img src="<?=$mz_weap3_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php 
?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php 

    } 
      if ($rand == 3) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uWeapon42=uWeapon42+$zoidmany,uAttackTurns=uAttackTurns+'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>You see something shiny in the distance, What is that you wonder?</b></center><br /><?php 
     ?><center><b>You just found a fully working <?=$wp_42_nm?>!<img src="<?=$wp_42_image?>"/></b></center><br /><?php 
     ?><center><b>No need for excavation tools here, This bad boy runs!</b></center><br /><?php 
    } 
     if ($fight2 > $defensetotal) { 
} 
    elseif ($rand == 4) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold+$goldgive3,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a group of <?=$wp_43_nm?>'s <img src="<?=$wp_43_image?>"/>.</b></center><br /> <?php 
     ?><center><b>You managed to fend them off and scored a nice <?=$goldgive3?> gold!</b></center><br /></b></center><br /><?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight2?></b></center><br /></b></center><br /><?php 
    } 
    if ($fight2 < $defensetotal) { 
} 
    elseif ($rand == 4) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold-$goldtake2,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a pack of <?=$wp_43_nm?>'s <img src="<?=$wp_43_image?>"/>.</b></center><br /><?php 
     ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake2?> Gold!</b></center><br /><?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight2?></b></center><br /></b></center><br /><?php 
    } 
      if ($fight1 > $defensetotal) { 
} 
    elseif ($rand == 5) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold+$goldgive2,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a group of <?=$wp_32_nm?>'s <img src="<?=$wp_32_image?>"/>.</b></center><br /> <?php 
     ?><center><b>You managed to fend them off and scored a nice <?=$goldgive2?> gold!</b></center><br /></b></center><br /><?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight1?></b></center><br /></b></center><br /><?php 
    } 
    if ($fight1 < $defensetotal) { 
} 
    elseif ($rand == 5) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold-$goldtake1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a pack of <?=$wp_32_nm?>'s <img src="<?=$wp_32_image?>"/>.</b></center><br /><?php 
     ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake1?> Gold!</b></center><br /><?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight1?></b></center><br /></b></center><br /><?php 
    } 
    if ($rand == 6 || $rand == 7) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold-$gold1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just got ambushed. You loose 50 gold!</b></center><br /><?php 
    } 
      if ($rand == 8 || $rand == 9 || $rand == 10 || $rand == 11 ) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>After a long hard journey you come up empty handed!</b></center><br /><?php 
    } 
    if ($excav1 > $user['uExcavation2']) { 
} 
    elseif ($rand == 12) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uEleshotbrhinosweap=uEleshotbrhinosweap+$zoidmany,uExcavation2=uExcavation2-$excav1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap6_nm?>. <img src="<?=$mz_weap6_image?>"/>You decide to keep it!</b></center><br /><?php 
    } 
    if ($excav2 = $user['uExcavation2']) { 
} 
    elseif ($rand == 12) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$zoidmany?> <?=$mz_weap6_nm?>. <img src="<?=$mz_weap6_image?>"/> But you have no excavation tool! You cannot excavate</b></center><br /><?php 
    ?><center><b>Tools needed: 1 <img src="<?=$excav_image2?>"/> </b></center><br /><?php 
    } 
     if ($fight3 > $defensetotal) { 
} 
    elseif ($rand == 13) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold+$goldgive4,uWeapon48=uWeapon48+$zoidmany,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a group of <?=$wp_48_nm?>'s <img src="<?=$wp_48_image?>"/>.</b></center><br /> <?php 
     ?><center><b>You managed to fend them off and scored a nice <?=$goldgive4?> gold!</b></center><br /></b></center><br /><?php 
     ?><center><b>You also managed to take a fully working <?=$wp_48_nm?>, <img src="<?=$wp_48_image?>"/>.</b></center><br /> <?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight3?></b></center><br /></b></center><br /><?php 
    } 
    if ($fight3 < $defensetotal) { 
} 
    elseif ($rand == 13) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold-$goldtake3,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You were attacked by a pack of <?=$wp_48_nm?>'s <img src="<?=$wp_48_image?>"/>.</b></center><br /><?php 
     ?><center><b>Your defense couldn't hold up to their might! You loose <?=$goldtake3?> Gold!</b></center><br /><?php 
     ?><center><b>YOUR DEFENSE: <?=$defensetotal?></b></center><br /></b></center><br /><?php 
     ?><center><b>THEIR ATTACK: <?=$fight3?></b></center><br /></b></center><br /><?php 
    } 
     if ($rand == 14 || $rand == 15 || $rand == 16 || $rand == 17 ) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET ugold=ugold+$goldgive1,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just stumbled across <?=$goldgive1?> Gold. You decide to keep it!</b></center><br /><?php 
    } 
     if ($rand == 18 || $rand == 19 || $rand == 20 || $rand == 21 ) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uMiners=uMiners+$miner,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just found <?=$miner?> miners, your forcing them to join you!</b></center><br /><?php 
    } 
if ($turns > $user['uAttackTurns']) { 
} 
    elseif ($rand == 22) { 
     $rand_cash = rand(1, 50); 
     $db->query("UPDATE users SET uAttackTurns=uAttackTurns-$turns,uAttackTurns=uAttackTurns-'$turns' WHERE uID='" . $user['uID'] . "'"); 

?><center><b>This Exploration costed you 5 Turns</b></center><br /><?php 
     ?><center><b>You just lost an additional <?=$turns?>. Better luck next time!</b></center><br /><?php 
    } 

require 'includes/footer.php'; 

?> 
+0

Это номер строки? Это поможет проследить его. Кроме того, 'else ($ rand == 12) {' не собирается работать - это должно быть другое 'elseif'? В вашем коде есть несколько из них. – andrewsi

+0

Вы можете просто удалить свой первый тестовый код, потому что все думают, что у вас с тобой проблемы. – Jason

+0

Рад, что это вы, который должен поддерживать этот код, а не я. Обычно, когда я начинаю думать «if elseif», мне нужно перефакторировать мой код с лучшей структурой/методами. –

ответ

0

Пользователи получают больше оборотов, потому что вы не делаете ничего, что мешает им это делать. Положите остальную часть вашего кода при помощи else {} после первого if заявления:

if($turns > $user['uAttackTurns']) { 
    echo "You don't have enough turns."; 
} 
else { 

    /*** Carry on As Usual ***/ 
} 

Это предотвратит любой другой запуск кода, если $turnsбольше$user['uAttackTurns'].

Кроме того, вам не нужно переопределять $rand = rand(1, 22);. Вы объявляете его один раз выше и снова после первого оператора if.

+0

Это было на самом деле то, что исправило мою проблему! Огромное спасибо. ELSE - это то, что мне нужно, чтобы все встало на свои места, как хорошая головоломка. –

1

Это случайное Шоуда внутри, вы can'do это

if (condition) 
{ 
//code 
} 
//another code 
elseif (condition) 
{ 
//code 
} 

так что вы должны изменить свой код здесь:

if ($turns > $user['uAttackTurns']) { 
     echo "You don't have enough turns."; 
     $rand = rand(1, 22); 
}  
elseif 
//code... 

EDIT:

Существует нет состояние после еще, поэтому

else(condition) 
{ 
//code 
} 

произведет еще одну ошибку. Последнее будет сделано, если все остальное не получится.

+0

Это работает, спасибо! –

+0

Спасибо за помощь всем, я закончил тем, что хорошо учился во время этого. оцените это –

0

Ошибка довольно краткий. «неожиданный T_ELSEIF» - как еще я могу сделать это проще? Существует ElseIf, что не ожидали, там не должно быть, находится в неправильном месте ...

Вы не дали строку или код, где это происходит, но я предполагаю, что это это:

if ($turns > $user['uAttackTurns']) { 
     echo "You don't have enough turns."; 
} 
    $rand = rand(1, 22); 
elseif ($excav1 > $user['uExcavation2']) { 
} 

Так делать еще, ElseIf, и т.д., вы должны следовать из одной фигурной скобки в другой ..

if (something) 
    { 
    whatever 
    } 
elseif (something else) 
{ 
    whatever else 
} 

Кроме того, я не вижу, что вы на самом деле с помощью $rand вара внутри если/ElseIf , так есть ли недостающий код? Если вам это нужно на каждом if/else, поместите его в elseif.

0

Это потому, что у вас есть заявление $rand = rand(1, 22); между вашим первым «если» и первым «elseif». «Elseif» должен непосредственно следовать за «if» без каких-либо инструкций между ними.