Jump to content

Printing multiple lines - not working ??


bsprogs

Recommended Posts

Hey everyone,

I'm new to php programming and I'm currently trying to have my script print multiple lines using a single print statement.
Here is my original code in html

[code]<form name="form1" method="POST" action="<?php print $_SERVER['PHP_SELF']?>">
  <div align="left">Username:
    <input type="text" name="username" value="<?php ('username') ?>"/>
      <br />
    Password:
  <input type="password" name="password" value="<?php ('password') ?>"/>
  <input type="submit" value="Add User" />
  </div>
</form>
[/code]

I looked and I found this command
<?php
print <<<ANYTHING
Print information here
ANYTHING;
?>

Here is the code I actually used:
[code]
<?php
print <<<TEST
<form name="form1" method="POST" action="$_SERVER['PHP_SELF']">
  <div align="left">Username:
    <input type="text" name="username" />
      <br />
    Password:
  <input type="password" name="password" />
  <input type="submit" value="Add User" />
  </div>
</form>
TEST;
?>
[/code]

When I run that code I get the following error

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/myusername/public_html/game/index.php on line 140

Line 140 contains this line of code
[code]
<form name="form1" method="POST" action="$_SERVER['PHP_SELF']">
[/code]

I have no idea why this is not working. I've checked other examples and used the direct examples and I get the same error with any code I try to use.

Is there something I need to turn on in the PHP.ini file?

I did however get this to work :-/
[code]
<?php
print "<form name=\"form1\" method=\"POST\" action=".$_SERVER['PHP_SELF'].">";
print  "<div align=\"left\">Username:\n";
print    "<input type=\"text\" name=\"username\"/>";
print      "<br />\n";
print    "Password:";
print  "<input type=\"password\" name=\"password\" />";
print  "<input type=\"submit\" value=\"Add User\"  />";
print  "</div>";
print "</form>";
?>
[/code]

It would be nice to be able to cut it a little shorter if possible though :) Thanks
Link to comment
Share on other sites

You should add cury braces around your variables in a HEREDOC statement like so:
{$_SERVER['PHP_SELF']}

otherwise you'll get the error message you are curtrently getting. Wrapping curly brakets around a variable shows PHP where the variable starts and ends basically.
Link to comment
Share on other sites

[!--quoteo(post=372224:date=May 8 2006, 01:26 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ May 8 2006, 01:26 AM) [snapback]372224[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You should add cury braces around your variables in a HEREDOC statement like so:
{$_SERVER['PHP_SELF']}

otherwise you'll get the error message you are curtrently getting. Wrapping curly brakets around a variable shows PHP where the variable starts and ends basically.
[/quote]

Perfect. Its funny that I never ran across anything mentioning that. Thanks a lot :)
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.