Jump to content

Error trying to echo html


essjay_d12

Recommended Posts

I have the following error pointing at the first echo line...

Parse error: parse error, unexpected T_LNUMBER, expecting ',' or ';'

[code] <?php
if (isset($_SESSION['username'])) {

    echo "<td width="143" height="107" valign="top"><p>You are logged in....</p><p>Welcome";
    echo $_SESSION['username'];
    echo "</p><p><a href="logout.php">logout</a></p></td>";

                        }
if (!isset($_SESSION['username'])) {

    echo "<td width="143" height="107" valign="top"><form id="form1" name="form1" method="post" action="auth2.php">Username:<input type="text" name="username" />Password:<input type="password" name="password" /><input type="submit" name="Submit2" value="Login" /><a href="register.php">Register</a></form></td>";

                        }
?>[/code]

What is wrong there? is it the quotes conflicting?
Link to comment
https://forums.phpfreaks.com/topic/4929-error-trying-to-echo-html/
Share on other sites

When ever you have double quotes in a string delimited by double quotes you need to escape them or you can surround the string with single quotes.
[code]<?php
    echo "<td width=\"143\" height=\"107\" valign=\"top\"><p>You are logged in....</p><p>Welcome";
    echo $_SESSION['username'];
    echo "</p><p><a href=\"logout.php\">logout</a></p></td>";
?>[/code]
or
[code]<?php
    echo '<td width="143" height="107" valign="top"><p>You are logged in....</p><p>Welcome';
    echo $_SESSION['username'];
    echo '</p><p><a href="logout.php">logout</a></p></td>';
?>[/code]

I prefer the second method since it's more readable be humans.

Ken
[!--quoteo(post=354913:date=Mar 14 2006, 10:31 AM:name=Essjay_d12)--][div class=\'quotetop\']QUOTE(Essjay_d12 @ Mar 14 2006, 10:31 AM) [snapback]354913[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I took the quotes out of the html part and it works, but I was wondering if this would have an effect later on somewhere?
[/quote]

you really don't want to remove the quotes, as then your markup won't validate, but if you use the suggestion above and simply escape the quotes with backslashes, you should be fine.

Archived

This topic is now archived and is closed to further replies.

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