This is a discussion on Variables not printing in HTML within the PHP Language forums, part of the PHP Programming Forums category; In the middle of an HTML document, I am adding some php code to display some text only if a ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
In the middle of an HTML document, I am adding some php code to display
some text only if a variable is set. Here is my code: <? $people = $_POST['people']; $people_fee= $people * 10; $people_text='<tr bgcolor="#ffffff"> <td valign="top"width="25%"><font size="2" color="black" face="arial">Extra people</td> <td valign="top" width="60%" align="left"><font size="2" color="black" face="arial">Analysis of, or compatibility with, <? print($people); ?> other person(s) (first person included without charge) </td> <td valign="top" width="15%" align="left"><font size="2" color="black" face="arial"><?print( $people_fee)?><br> </td> </tr>'; if ($people) { print ($people_text); } ?> The above partially works. If $people has anything in it, the HTML displays the text saying "Extra people," etc. But the value of $people and $people_fee do not print out. Why is this? Thank you. |
|
|||
|
.oO(Robert)
>In the middle of an HTML document, I am adding some php code to display >some text only if a variable is set. Here is my code: > ><? >[...] > >The above partially works. If $people has anything in it, the HTML >displays the text saying "Extra people," etc. But the value of $people >and $people_fee do not print out. Why is this? Have a look at the generated HTML code, it should give you an idea what's wrong. Micha |
|
|||
|
On 21 Jan 2005 17:01:47 -0800, "Robert" <robert1111@starcenter.com> wrote:
>In the middle of an HTML document, I am adding some php code to display >some text only if a variable is set. Here is my code: > ><? >$people = $_POST['people']; >$people_fee= $people * 10; > >$people_text='<tr bgcolor="#ffffff"> ><td valign="top"width="25%"><font size="2" color="black" >face="arial">Extra people</td> ><td valign="top" width="60%" align="left"><font size="2" >color="black" face="arial">Analysis of, or compatibility with, <? >print($people); ?> other person(s) (first person included without >charge) ></td> ><td valign="top" width="15%" align="left"><font size="2" color="black" >face="arial"><?print( $people_fee)?><br> You're trying to embed PHP inside a PHP string - this won't then execute as PHP, it'll just come out as <?print ... etc., which looks like an unknown tag, which browsers will then just ignore. If you want variable's value in the string, then either: (a) Use double quotes, and lose the '<?print(' and '?>' (b) Concatenate it in, i.e. $people_text = '...arial">' . $people_fee . '<br>...'; ></td> ></tr>'; > >if ($people) { >print ($people_text); >} >?> > >The above partially works. If $people has anything in it, the HTML >displays the text saying "Extra people," etc. But the value of $people >and $people_fee do not print out. Why is this? -- Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool |