php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16576 Else if fails when seperated @ least
Submitted: 2002-04-12 15:18 UTC Modified: 2002-04-12 16:15 UTC
From: josephcohen11 at yahoo dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.1.2 OS: Windows 2000
Private report: No CVE-ID: None
 [2002-04-12 15:18 UTC] josephcohen11 at yahoo dot com
if i have html and then i embed php, i cannot use else if, only if (which REALLY SUCKS for forms.)
this isn't my code but it illustrates the issue
example:
You should see an X int the slot you selected:<br>
<?php if($HTTP_GET_VARS['Slot']==1) echo 'X';?>:<?php else if($HTTP_GET_VARS['Slot']==2) echo 'X';?>:

etc.
Adding curlies to the ifs and parentheses to the echo don't help.

please email me a fix if its my mistake, or fix the bug if its yours
thanks,
   joe

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-12 15:24 UTC] sander@php.net
The bug system is not the appropriate forum for asking support
questions. For a list of a range of more appropriate places to ask
for help using PHP, please visit http://www.php.net/support.php

Hint: elseif is ONE word
 [2002-04-12 16:15 UTC] hholzgra@php.net
"else if" and "else if" are both valid, 
the problem is that control structures in
the "normal" form may not be split across
several <?php ... ?> blocks this way

<?php if(...) { ?> ... <?php } else if{...) { ?> ... <?php } ?> 

is ok as the mode switch occures inside the curlies
but with 

<?php if(...) echo ...; ?> ... <?php else if{...) echo ...; ?>

the echo and the ?>...<?php count as two statements, 
so the connection between the "if" and the "else" is lost

the "alternative" form might help here?:

<php if(...): echo ...; ?> ... <?php elseif(...): echo ...; ?>

note the colons after the closing parentheses and that in this case it's really only "elseif", not "else if"
 [2002-04-12 18:50 UTC] josephcohen11 at yahoo dot com
That works except now I'm getting a parse error on the curly that ends the function
is there something i need to do to end that chain or something?

thanks,
   joe

and to the first guy who replied, look @ the online documentation before you bother people, i did, and i tried BOTH else ifs as a result, although i admit i did else if first because im a c programmer
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Aug 11 07:00:03 2025 UTC