Variables not printing in HTML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robert

    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="#fffff f">
    <td valign="top"wid th="25%"><font size="2" color="black"
    face="arial">Ex tra people</td>
    <td valign="top" width="60%" align="left"><f ont size="2"
    color="black" face="arial">An alysis of, or compatibility with, <?
    print($people); ?> other person(s) (first person included without
    charge)
    </td>
    <td valign="top" width="15%" align="left"><f ont 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.

  • Andy Hassall

    #2
    Re: Variables not printing in HTML

    On 21 Jan 2005 17:01:47 -0800, "Robert" <robert1111@sta rcenter.com> wrote:
    [color=blue]
    >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="#fffff f">
    ><td valign="top"wid th="25%"><font size="2" color="black"
    >face="arial">E xtra people</td>
    ><td valign="top" width="60%" align="left"><f ont size="2"
    >color="black " face="arial">An alysis of, or compatibility with, <?
    >print($people) ; ?> other person(s) (first person included without
    >charge)
    ></td>
    ><td valign="top" width="15%" align="left"><f ont size="2" color="black"
    >face="arial">< ?print( $people_fee)?>< br>[/color]

    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>...';
    [color=blue]
    ></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?[/color]

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Michael Fesser

      #3
      Re: Variables not printing in HTML

      .oO(Robert)
      [color=blue]
      >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?[/color]

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

      Micha

      Comment

      Working...