Error when using multiple else/if and elseif statements?

Discussion in 'PHP' started by Anveto, Aug 15, 2011.

  1. #1
    I am currently writing a script and cant figure out why there is a conflict? How can i fix this?

    if($a == X)
    {
    	if(X !== $b){
    	echo $a_1+$b_1+$b_2;
    	}else{
    	echo $a_1+$b_1+$c_1;
    	}
    }
    elseif($a_2 == /)
    {
    echo $a_1+$a_2+$b_1;
    }
    else
    {
    echo $a_1+$a_2;
    }
    echo '</td><td>'. $b. ' | ' ;
    if($b == X)
    {
    echo ' ';
    }
    else
    {
    echo $b_2;
    }
    PHP:

     
    Solved! View solution.
    Anveto, Aug 15, 2011 IP
  2. MancuZ28

    MancuZ28 Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    21
    #2
    Edit: I think I gave bad info...let me think about that some more...can you post the error?
     
    MancuZ28, Aug 15, 2011 IP
  3. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #3
    Thanks, I am not getting any specific error in any error log, it simply says there is an error on line 9, 13 and 24. So on elseif, else, and echo $b_2 it says there is some kind of error
     
    Anveto, Aug 15, 2011 IP
  4. #4
    What is this line checking?

    elseif($a_2 == /)

    If you're trying to compare a string you'll need quotes: "/"
     
    Last edited: Aug 15, 2011
    MancuZ28, Aug 15, 2011 IP
  5. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #5

    Thanks, that solved the problem. Didnt even consider that the / was an issue :D
     
    Anveto, Aug 15, 2011 IP
  6. Technoslab

    Technoslab Peon

    Messages:
    46
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    0
    #6
    / is an operator so without quotes it would obviously give an error.

    
    echo a; // Outputs a + notice level error
    echo /; // Gives error
    echo 'a'; // No error
    echo '/'; // No error
    
    Code (markup):
     
    Technoslab, Aug 16, 2011 IP