Variables not printing in HTML

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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
<td valign="top" width="15%" align="left"><font size="2" color="black"
face="arial"><?print( $people_fee)?><br>

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.

Re: Variables not printing in HTML

Quoted text here. Click to load it

 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>...';

Quoted text here. Click to load it

< Space: disk usage analysis tool

Re: Variables not printing in HTML


Quoted text here. Click to load it

Have a look at the generated HTML code, it should give you an idea
what's wrong.


Site Timeline