Page 1 of 1
Elseif Help - PHP Virgin!
Posted: Fri May 15, 2009 4:30 am
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.
Re: Elseif Help - PHP Virgin!
Posted: Fri May 15, 2009 5:04 am
by jaoudestudios
You are not closing the abovoe if statement. You need to add a }.
Re: Elseif Help - PHP Virgin!
Posted: Fri May 15, 2009 5:07 am
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.
Re: Elseif Help - PHP Virgin!
Posted: Fri May 15, 2009 5:24 am
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.)
Re: Elseif Help - PHP Virgin!
Posted: Fri May 15, 2009 5:58 am
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.
Re: Elseif Help - PHP Virgin!
Posted: Fri May 15, 2009 6:02 am
by jaoudestudios
Sorry I explained myself badly.
Every conditional statement needs to be closed.
Change this line
To...
NB: You should use full php tags.
Re: Elseif Help - PHP Virgin!
Posted: Fri May 15, 2009 6:08 am
by godrob
Thank you so much, that's fixed it!
I really appreciate all your help
Rob.
Re: Elseif Help - PHP Virgin!
Posted: Fri May 15, 2009 7:28 am
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!