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
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
Link to comment
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.
Link to comment
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.