could not understand HERE in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

could not understand HERE in php

Post 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;
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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>
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post 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?
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

thats it buddy. It is working fine.
thank you, thank you very much.Could not express myself.
thanks
saumya
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post 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
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

if you don't post what changes you made and show us the new code, we can't help you.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post 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>
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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>
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

Thank you very much. its working now.
Post Reply