Use of PHP isset for a submit form


/ Published in: PHP
Save to your folder(s)

Simple PHP tutorial on how to use isset.


Copy this code and paste it in your HTML
  1. <!DOCTYPE html
  2. PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  5. <head>
  6. <title>PHP Test</title>
  7. </head>
  8. <body>
  9. <?php
  10. if(!isset($_POST['submit'])){
  11. ?>
  12.  
  13. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  14. Enter your age: <input name="age" size="2">
  15. <input type="submit" name="submit" value="Go">
  16.  
  17. <?php
  18. } else {
  19. //Grab the text we input
  20. $input = $_POST['age'];
  21.  
  22. if($input < 27){
  23. echo "You are young";
  24. } elseif($input == 27){
  25. echo "The perfect age";
  26. } elseif($input > 27){
  27. echo "You are old!";
  28. }
  29. }
  30. ?>
  31. </body>
  32. </html>

URL: http://devzone.zend.com/node/view/id/628

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.