$_POST - Used to collect form data after submitting an HTML form. Also used to pass variables


SUBMITTED BY: henry1874w

DATE: June 17, 2017, 1:20 p.m.

FORMAT: Text only

SIZE: 422 Bytes

HITS: 202

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  5. Name: <input type="text" name="fname">
  6. <input type="submit">
  7. </form>
  8. <?php
  9. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  10. // collect value of input field
  11. $name = $_POST['fname'];
  12. if (empty($name)) {
  13. echo "Name is empty";
  14. } else {
  15. echo $name;
  16. }
  17. }
  18. ?>
  19. </body>
  20. </html>

comments powered by Disqus