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.
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
The script can actually go anywhere, but the
echostatement 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$wordwould 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?