Jump to content

[SOLVED] multiple if's... T_ELSEIF error


MasterACE14

Recommended Posts

The problem is, I have multiple if's and am lost in the order now  :-\ , its now throwing me a error after adding a few else's

 

code:

<?php if($player['currenthealth'] >= 1 && $player['tcf_check'] == 0 && $other_player['tcf_check'] == 0 && $other_player['allianceid'] != $player['allianceid'] && $other_player['alliancename'] != $player['alliancename']) { 

if($other_player['alliancename'] == "none" && $player['currenthealth'] >= 1 && $player['tcf_check'] == 0 && $other_player['tcf_check'] == 0) {

if($other_player['location'] == "At War" && $player['location'] == "At War") {
?>

<tr>

<form name="player_interaction_attack" method="post" action="index.php?page=player_interaction_result">

<td><center> Ammo: </center></td>		<td><center> <input type="text" size="4" maxlength="10" name="ammo"> / 20 </center></td>
		<input type="hidden" name="otherplayersid" value="<?=$other_player['id']?>">
	<td><center> <input type="submit" value="Attack" onClick="return checksubmit(this)"> </center></td>
</form>

</tr>

<tr><td> </td></tr>

<?php 
} else { die("<center>You can not attack someone when you are At Home or they are At Home</center>"); } 
} else { die("<center>You can not attack someone if your health is zero and if you are on Temporary Cease Fire</center>"); } 
} 
?>

<?php elseif($player['currenthealth'] == 0) { // this is line 225 ?>

 

error:

Parse error: syntax error, unexpected T_ELSEIF in /home/ace/public_html/conflictingforces/lib/player_interaction.php on line 225

 

any help is greatly appreciated

 

Regards ACE

Link to comment
https://forums.phpfreaks.com/topic/112404-solved-multiple-ifs-t_elseif-error/
Share on other sites

<?php
  if ($player['currenthealth'] >= 1 && $player['tcf_check'] == 0 && $other_player['tcf_check'] == 0 && $other_player['allianceid'] != $player['allianceid'] && $other_player['alliancename'] != $player['alliancename']) {
      if ($other_player['alliancename'] == "none" && $player['currenthealth'] >= 1 && $player['tcf_check'] == 0 && $other_player['tcf_check'] == 0) {
          if ($other_player['location'] == "At War" && $player['location'] == "At War") {
?>

<tr>

<form name="player_interaction_attack" method="post" action="index.php?page=player_interaction_result">

<td><center> Ammo: </center></td>    <td><center> <input type="text" size="4" maxlength="10" name="ammo"> / 20 </center></td>
      <input type="hidden" name="otherplayersid" value="<?=$other_player['id']?>">
    <td><center> <input type="submit" value="Attack" onClick="return checksubmit(this)"> </center></td>
</form>

</tr>

<tr><td> </td></tr>

<?php
              } else
              {
                  die("<center>You can not attack someone when you are At Home or they are At Home</center>");
              }
          } else {
              die("<center>You can not attack someone if your health is zero and if you are on Temporary Cease Fire</center>");
          }
      }
?>

<?php
      elseif ($player['currenthealth'] == 0) {
          // this is line 225 
?>

are all the nested if's supposed to be separate conditionals? or is it "if this... then if this... then if this... then do whatever" or is it "if this, then this, else if this, then this, else if..." ?

 

And change the last to "else if". you need a space between the 2.

I've just fixed the error, but its now echoing something it shouldn't.

 

<?php
  if ($player['currenthealth'] >= 1 && $player['tcf_check'] == 0 && $other_player['tcf_check'] == 0 && $other_player['allianceid'] != $player['allianceid'] && $other_player['alliancename'] != $player['alliancename']) {
      if ($other_player['alliancename'] == "none" && $player['currenthealth'] >= 1 && $player['tcf_check'] == 0 && $other_player['tcf_check'] == 0) {
          if ($other_player['location'] == "At War" && $player['location'] == "At War") {
?>

<tr>

<form name="player_interaction_attack" method="post" action="index.php?page=player_interaction_result">

<td><center> Ammo: </center></td>    <td><center> <input type="text" size="4" maxlength="10" name="ammo"> / 20 </center></td>
      <input type="hidden" name="otherplayersid" value="<?=$other_player['id']?>">
    <td><center> <input type="submit" value="Attack" onClick="return checksubmit(this)"> </center></td>
</form>

</tr>

<tr><td> </td></tr>

<?php
              } else
              {
                  echo("<center>You can not attack someone when you are At Home or they are At Home</center>");
              }
		  
          } else {
              echo("<center>You can not attack someone if your health is zero and if you are on Temporary Cease Fire</center>");
          }
	  
      } elseif ($player['currenthealth'] == 0) { // this is line 225 
?>

 

it's echoing...

You can not attack someone if your health is zero and if you are on Temporary Cease Fire

 

EDIT: its displaying that because users are default placed in the alliance 'none'.

but to the game this is scene as an alliance.

 

any ideas on how to fix up the IF to make it so it displays the form regardless of what alliance the logged in user ($player) is in. As long as it isn't the same as the one the logged in user is in(with the exception of the alliance 'none')

Problem solved.

 

I created a alliance name, and alliance id variable, then did a if statement to check if the other players alliance name was equal to 'none' and if there alliance id is equal to zero, and if it is I appended a random number to the end of the alliance name and the id and use that in my if statement to check whether to display the form or not.

 

Thanks for your help people.  ;D

 

Regards ACE

Archived

This topic is now archived and is closed to further replies.

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