html - Can someone explain this sample PHP code for me? -


i doing independent study on php , html in w3school , don't understand following codes: (copied w3school)

1  <!doctype html> 2  <html> 3  <body> 4 5  <form method="post" action="<?php echo $_server['php_self'];?>"> 6    name: <input type="text" name="fname"> 7    <input type="submit"> 8  </form> 9 10 <?php 11 if ($_server["request_method"] == "post") { 12     // collect value of input field 13     $name = $_post['fname'];  14     if (empty($name)) { 15         echo "name empty"; 16     } else { 17         echo $name; 18     } 19 } 20 ?> 21  22 </body> 23 </html> 

q1: why can i, , how should insert php code in middle of bunch of html codes sample did in line 5? topic should @ learn more kind of operation?

q2: in php codes after line 10, why want include if statement decide if request method "post"? can't go other if condition, in 1 check text box empty?

appreciate help(:

answer of question 1:

  • you can add php code anywhere in html document. have use <?php start , ?> end.

answer of question 2:

  • you have include if statement decide request post because have given post method in form. can learn more form , attributes here

  • you have write php code in page because have mentioned $_server['php_self'] in action attribute means form data sent this(self) page through post method. -you can learn method here


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -