homepage Welcome to WebmasterWorld Guest from 54.205.193.39
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

    
Leaving and returning to parsing mode in PHP
Getting an error message on leaving parsing mode
Cassil




msg:4246256
 5:04 pm on Dec 26, 2010 (gmt 0)

I'm new to using PHP and am trying to write a script to handle input from a form. I need to output one of a selection of large blocks of HTML depending on the users input. I was hoping to do this by exiting parsing mode (with ?>) before the block of HTML and returning to parsing mode (with <?php) to continue the script. However, when I run this I get a parsing error "unexpected $END".

So I wrote a short simple script to try to identify what the problem was but get the same error message. Writing this same script but using "echo" instead of exiting parsing mode works. Doing that is fine for this short test script but would be tedious for the real thing.

I did wonder if it was because the only thing I have in the if statements is exiting to HTML mode but I got the same error when I added some more things into the if statements.

The test code that causes the error "unexpected $END" is:

<?php
if ($_POST["num"] < 10)
{
?>
<p>The user typed a number less than ten.</p>
<?php
}
if (_POST["num"] >= 10)
{
?>
<p>The user typed a number equal to or greater than ten.</p>
<php
}
?>

The test code that works is:

<?php
if ($_POST["num"] < 10)
{
echo "<p>The user typed a number less than ten.</p>";
}
if (_POST["num"] >= 10)
{
echo "<p>The user typed a number equal to or greater than ten.</p>";
}
?>

Am I doing something wrong with leaving and returning to parsing mode or could this be to do with how PHP parsing is set up on the server?

Thanks in advance for any help.

 

getcooking




msg:4246324
 3:35 am on Dec 27, 2010 (gmt 0)

For starters:
<p>The user typed a number equal to or greater than ten.</p>
<php
}
?>

should be:
<p>The user typed a number equal to or greater than ten.</p>
<?php
}
?>


and

if (_POST["num"] >= 10)


Should be:
if ($_POST["num"] >= 10)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved