Advertisement
Guest User

rectanglearea.php

a guest
Aug 29th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. <body background = "a.png">
  2.  
  3. <form action="rectanglearea.php" method="post">
  4.  
  5. <center>
  6. <br>
  7. <br>
  8. <br>
  9. <br>
  10. <br>
  11. <br>
  12. <br>
  13. <br>
  14. <br>
  15. <h3>Please enter the Length and the Width of your rectangle.</h3>
  16.  
  17. Enter length: <input type="text" name="textL" placeholder= "Enter number"/> //textfield to enter the length, only integer is allowed, it will return to the text field when you type letter
  18. <br>
  19. <br>
  20. Enter width: <input type="text" name="textW" placeholder= "Enter number"/> //same as length, it's to enter the width.
  21. <br>
  22. <br>
  23. <input type="submit" value="Submit" /> here is to submit the length and width
  24. <br>
  25. <br>
  26. </form>
  27.  
  28. <?php
  29. if(isset($_POST['textL']) && isset($_POST['textW'])){  //to get the number you've been entered on the text field & also to specify on what will be calculated.
  30. if(!empty($_POST['textL']) && !empty($_POST['textW'])){ //it's specify that when you entered nothing on the textfield the submit will not proceed to calculation.
  31. if(!preg_match("([0-9])",$_POST['textL']) || !preg_match("([0-9])",$_POST['textW'])){
  32. echo 'Enter only numbers.';
  33. }
  34. else{
  35. $l = $_POST['textL'];
  36. $w = $_POST['textW'];
  37. echo "The rectangle with length $l and width $w has an area of ".calculate($l,$w); //the output of calculation.
  38. }
  39. }
  40. }
  41.  
  42. function calculate($length, $width){
  43. $area = $length * $width; //the calculation of the rectangle area.
  44. return $area;
  45. }
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement