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
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 
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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')

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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