tags:

views:

72

answers:

1

I am a noob to PHP just wondering why are we writing the php script in the body tag of HTML.

I am just taking a word on one page and directing it to another page using the post method. below is the code.

page1.html

<form action="disp.php" method="post">
Enter a word: < input type="text" name="word" />

disp.php

this goes inside the body tag

$word=$_POST['word'];
echo $word;

All your help is highly appreciated.

+7  A: 

One way to think of it is that the server dynamically creates an HTML page based on the result of your PHP script. For it to be valid html, you need to write the appropriate tags such as

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>
  <head>
  ...
  </head>
  <body>
  ...
  </body>
</html>

The script can actually go anywhere, but the echo statement is like saying "write something here." If you had it echo something between <title></title> tags, then the result of your PHP statement, in this case $word would appear in the page title. You want it to appear in the body of the page, so you have it echo the variable between <body></body> tags.

Does that answer your question?

Chris Thompson
yup dude thanks a lot it helps.
Josh
To be **valid** HTML you need a DOCTYPE and a few other things, but that's another story. ;-D
pavium
@pavium touche, you caught my laziness ;-)
Chris Thompson