Jump to content

Archived

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

essjay_d12

Error trying to echo html

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[!--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.

Share this post


Link to post
Share on other sites

×

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.