Page 1 of 1

could not understand HERE in php

Posted: Tue May 03, 2005 6:09 am
by saumya
i am following a book and there its written

Code: Select all

<html>
 <head>
  <title>Persistence Demo</title>
 </head>
 
 <body>
  <h1>Persistence Demo</h1>

print <<<HERE
	some html codes.
HERE;

 </body>
</html>
but when i run it from my server it does not show me the html codes.it shows the <h1> lines in headers but does not show from <<<HERE. can any body tell me what that is for
print <<<HERE

HERE;

Posted: Tue May 03, 2005 6:45 am
by JayBird

Posted: Tue May 03, 2005 10:51 am
by Skara
you forgot your php brackets.

Code: Select all

<html>
blah blah blah
<?php
// place php code in here
// such as..
print <<<EOS
this is a bunch of text that will be printed...
blah blah blah
you can put ' and " without escaping them.
if you put {$foo}, it will be parsed.
this last line must be on the left edge of the screen (EOS;):
EOS;

?>
more html...
</html>

Posted: Thu May 05, 2005 2:56 am
by saumya
i am having problem here with this.

Code: Select all

<html>
 <head>
  <title>Persistence Demo</title>
 </head>
 
 <body>
  <h1>Persistence Demo</h1>
  <form>
  <?PHP
  //increment the counters
  $txtBoxCounter++;
  $hdnCounter++;
  
  print <<<HERE
  <input type="text" name="txtBoxCounter" value="$txtBoxCounter">
  <input type="hidden" name="hdnCounter" value="$hdnCounter">
  <h3>The Hidden Value is $hdnCounter</h3>
  <input type="submit" value="Click to increment">
  HERE;
  ?>
  </form>
 </body>
</html>
it does not show me anything in the browser.help me please

Posted: Thu May 05, 2005 3:27 am
by JayBird
RTM!! :twisted:

If you read the link i gave you, you would have noticed this
It is very important to note that the line with the closing identifier contains no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs after or before the semicolon.

Posted: Thu May 05, 2005 4:59 am
by saumya
could not got you?Please forgive me of my dumbness but explain.In my code there are nothing in the end.but still why not working?

Posted: Thu May 05, 2005 5:14 am
by phpScott
this is what i think he means

Code: Select all

<html>
 <head>
  <title>Persistence Demo</title>
 </head>
 
 <body>
  <h1>Persistence Demo</h1>
  <form>
  <?PHP
  //increment the counters
  $txtBoxCounter++;
  $hdnCounter++;
  
print <<<HERE
  <input type="text" name="txtBoxCounter" value="$txtBoxCounter">
  <input type="hidden" name="hdnCounter" value="$hdnCounter">
  <h3>The Hidden Value is $hdnCounter</h3>
  <input type="submit" value="Click to increment">
HERE;
  ?>
  </form>
 </body>
</html
you will note the differnce in that the HERE; is not indented anymore.

Posted: Thu May 05, 2005 5:40 am
by saumya
thats it buddy. It is working fine.
thank you, thank you very much.Could not express myself.
thanks
saumya

Posted: Thu May 05, 2005 6:24 am
by saumya
it ies working fine but why my variables are not updated each time i click the button.I was follwing a book, its said there that you should see the hidden variable update each time you click the button.

thanks
saumya

Posted: Thu May 05, 2005 6:32 am
by phpScott
do a search on this site for global variables and check out
Note that register_globals is going to be depracated (i.e., turned off by
default) in the next version of PHP, because it often leads to security bugs.
Read http://php.net/manual/en/security.registerglobals.php for further
information

it will have to do with you php.ini file and something called register_globals = off.


This is done for security reasons.

Posted: Thu May 05, 2005 6:34 am
by infolock
if you don't post what changes you made and show us the new code, we can't help you.

Posted: Thu May 05, 2005 6:42 am
by saumya
i am sorry.here is my code

Code: Select all

<html>
 <head>
  <title>Persistence Demo</title>
 </head>
 
 <body>
  <h1>Persistence Demo</h1>
  <form>
  <?PHP
  //increment the counters
  $txtBoxCounter++;
  $hdnCounter++;

  
  print <<<HERE
  <input type="text" name="txtBoxCounter" value="$txtBoxCounter">
  <input type="hidden" name="hdnCounter" value="$hdnCounter">
  <h3>The Hidden Value is $hdnCounter</h3>
  <input type="submit" value="Click to increment">
HERE;
  ?>
  </form>
 </body>
</html>

Posted: Thu May 05, 2005 10:01 am
by vigge89
saumya wrote:i am sorry.here is my code
<code>

Code: Select all

<html>
 <head>
  <title>Persistence Demo</title>
 </head>
 
 <body>
  <h1>Persistence Demo</h1>
  <form method="get">
  <?PHP
  //increment the counters
  $_GET['txtBoxCounter']++;
  $_GET['hdnCounter']++;

  
  print <<<HERE
  <input type="text" name="txtBoxCounter" value="{$_GET['txtBoxCounter']}">
  <input type="hidden" name="hdnCounter" value="{$_GET['hdnCounter']}">
  <h3>The Hidden Value is $hdnCounter</h3>
  <input type="submit" value="Click to increment">
HERE;
  ?>
  </form>
 </body>
</html>

Posted: Fri May 06, 2005 3:46 am
by saumya
Thank you very much. its working now.