bsprogs Posted May 8, 2006 Share Posted May 8, 2006 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 <<<ANYTHINGPrint information hereANYTHING;?>Here is the code I actually used:[code]<?phpprint <<<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 errorParse 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 140Line 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]<?phpprint "<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 https://forums.phpfreaks.com/topic/9295-printing-multiple-lines-not-working/ Share on other sites More sharing options...
wildteen88 Posted May 8, 2006 Share Posted May 8, 2006 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 https://forums.phpfreaks.com/topic/9295-printing-multiple-lines-not-working/#findComment-34242 Share on other sites More sharing options...
bsprogs Posted May 8, 2006 Author Share Posted May 8, 2006 [!--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 https://forums.phpfreaks.com/topic/9295-printing-multiple-lines-not-working/#findComment-34360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.