Elseif Help - PHP Virgin!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
godrob
Forum Newbie
Posts: 3
Joined: Fri May 15, 2009 4:06 am

Elseif Help - PHP Virgin!

Post by godrob »

Hi guys, I'm new to php and programming in general and would really appreciate some help with the elseif statement. The snippet of code below works just fine without elseif, but when I add <?elseif($confirmed=='2'){?> it errors.

Please advise?

Code: Select all

 
<?if($confirmed=='1'){?>
 
<tr><td colspan=2 valign="top" class="table_body" align=center>
<br><br><br><b>SOME TEXT 1</b><br><br>
 
<?elseif($confirmed=='2'){?>
 
<tr><td colspan=2 valign="top" class="table_body" align=center>
<br><br><br><b>SOME TEXT 2</b><br><br>
 
<?}else{?>
 
<table align="center" width="700"><tr><td width="700">
<p align="center" class="header">SOME TEXT 3</p>
</tr>
</td>
</table>
Thanks for any help you can offer

Rob.
Last edited by Benjamin on Fri May 15, 2009 8:24 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Elseif Help - PHP Virgin!

Post by jaoudestudios »

You are not closing the abovoe if statement. You need to add a }.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Elseif Help - PHP Virgin!

Post by onion2k »

For future reference, saying "it errors" is no help whatsoever. If you want help with an error tell people what the error message says.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Elseif Help - PHP Virgin!

Post by jaoudestudios »

onion2k wrote:For future reference, saying "it errors" is no help whatsoever. If you want help with an error tell people what the error message says.
I second that, you are more likely to get help if you paste the error message as this will contain a line number (this might not match the line numbers here, so make it clear which line it actually is.)
godrob
Forum Newbie
Posts: 3
Joined: Fri May 15, 2009 4:06 am

Re: Elseif Help - PHP Virgin!

Post by godrob »

Thanks for your replies.

I'm sorry for not providing you with the exact error. Here it is:

Parse error: syntax error, unexpected T_ELSEIF on line 185 (((( Line 185 in my code is <?elseif($confirmed=='2'){?> )))))

Here's the snippet of code again with the <?} added, but I still get the error

Code: Select all

<?if($confirmed=='1'){?>
 
<tr><td colspan=2 valign="top" class="table_body" align=center>
<br><br><br>SOME TEXT 1 <br><br></td></tr>
 
<?elseif($confirmed=='2'){?>
 
<tr><td colspan=2 valign="top" class="table_body" align=center>
<br><br><br><b>SOME TEXT 2<br><br></td></tr>
 
<?}else{?>
 
<table align="center" width="700"><tr><td width="700">
 
<p align="center" class="header">SOME TEXT 3</p>
</tr>
</td>
</table>
 
<?}
<?}?>
I've added the <?} as suggested and the <?}?> appears right at the foot of the code and works fine without the ELSEIF statement.

Please help?

Thanks
Rob.
Last edited by Benjamin on Fri May 15, 2009 8:24 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Elseif Help - PHP Virgin!

Post by jaoudestudios »

Sorry I explained myself badly.

Every conditional statement needs to be closed.

Change this line

Code: Select all

<?elseif($confirmed=='2'){?>
To...

Code: Select all

<?} elseif($confirmed=='2'){?>
NB: You should use full php tags.
godrob
Forum Newbie
Posts: 3
Joined: Fri May 15, 2009 4:06 am

Re: Elseif Help - PHP Virgin!

Post by godrob »

Thank you so much, that's fixed it!

I really appreciate all your help

Rob.
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: Elseif Help - PHP Virgin!

Post by crazycoders »

A good way to understand errors and fix invalid programming is often to look for the keyword "unexpected" in the parsing errors. Although it will not give you the exact line, it usually is because you forgot a } or a ; at the end of a statement or block.

"Unexpected {keyword}" simply tells you that before that exact portion of code around that line, you have forgotten something or you really placed that keyword incorrectly!
Post Reply