Variables not printing in HTML

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


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-22-2005
Robert
 
Posts: n/a
Default Variables not printing in HTML

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.

Reply With Quote
  #2 (permalink)  
Old 01-22-2005
Michael Fesser
 
Posts: n/a
Default Re: Variables not printing in HTML

.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
Reply With Quote
  #3 (permalink)  
Old 01-22-2005
Andy Hassall
 
Posts: n/a
Default Re: Variables not printing in HTML

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:16 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0