Jump to content

Recommended Posts

Can anybody tell me why this script below isn't working.  As you can see if page = names it will echo that.  The problem is inside the echo I have some php.  I tried putting the php in "" but it still comes up with an error.

[code]    <?

if ($page == 'names'){


echo"</td>
  </tr>
  <tr class=\"navtext2\">
    <td height=\"22\" colspan=\"3\" valign=\"top\"> <div id=\"navcontainer\">
       
      <div align=\"left\"><font color=\"#747474\">" echo $row_names['fullname']; "</font></div>
      </div>
      <div>
        <div align=\"left\"></div>
      </div>
      <div></div></td>
  </tr>";



}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/28995-php-inside-html/
Share on other sites

When you want to echo variables inside html, do not use echo use the period (.) before and after the variable.
[code]
<?

if ($page == 'names'){


echo"</td>
  </tr>
  <tr class=\"navtext2\">
    <td height=\"22\" colspan=\"3\" valign=\"top\"> <div id=\"navcontainer\">
       
      <div align=\"left\"><font color=\"#747474\">" .$row_names['fullname']."</font></div>
      </div>
      <div>
        <div align=\"left\"></div>
      </div>
      <div></div></td>
  </tr>";



}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/28995-php-inside-html/#findComment-132845
Share on other sites

[quote]When you want to echo variables inside html, do not use echo use the period (.) before and after the variable.[/quote]
Its ok for him, he is using double quotes, which you can echo out vars without having to use the period

The problem is probably this part though: echo $row_names['fullname'];

its already in an echo, you don't need to add another one, so change it to this:
[CODE]
    <?php

if ($page == 'names'){


echo"</td>
  </tr>
  <tr class=\"navtext2\">
    <td height=\"22\" colspan=\"3\" valign=\"top\"> <div id=\"navcontainer\">
       
      <div align=\"left\"><font color=\"#747474\"> {$row_names['fullname']} </font></div>
      </div>
      <div>
        <div align=\"left\"></div>
      </div>
      <div></div></td>
  </tr>";



}
?>[/CODE]
Link to comment
https://forums.phpfreaks.com/topic/28995-php-inside-html/#findComment-132848
Share on other sites

A better option is use the HEREDOC syntax, no need to escape any quotes:
[code=php:0]<?php

if ($page == 'names'){


echo <<<HTML_CODE
</td>
  </tr>
  <tr class="navtext2">
    <td height="22" colspan="3" valign="top"> <div id="navcontainer">
       
      <div align="left"><font color="#747474"> {$row_names['fullname']} </font></div>
      </div>
      <div>
        <div align="left"></div>
      </div>
      <div></div></td>
  </tr>
HTML_CODE;
// DO NOT INDENT OR PUT ANYTHING ON THE LINE ABOVE

}
?>[/code]

When using HEREDOC syntax you may need to wrap curly braces around your variable names ({$my_var}), especially if its an array.
Link to comment
https://forums.phpfreaks.com/topic/28995-php-inside-html/#findComment-132865
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.