Jump to content


Photo

Error trying to echo html


  • Please log in to reply
3 replies to this topic

#1 essjay_d12

essjay_d12
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 14 March 2006 - 03:08 PM

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

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

<?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>";

                        } 
?>

What is wrong there? is it the quotes conflicting?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 14 March 2006 - 03:18 PM

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.
<?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>";
?>
or
<?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>';
?>

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

Ken


#3 essjay_d12

essjay_d12
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 14 March 2006 - 03:31 PM

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?



#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 14 March 2006 - 03:41 PM

[!--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) View Post[/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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users