Welcome to WebmasterWorld Guest from 50.19.135.67

Forum Moderators: brotherhood of lan & mack

Message Too Old, No Replies

Leaving and returning to parsing mode in PHP

Getting an error message on leaving parsing mode

     

Cassil

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

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

5+ Year Member



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)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month