Advertisement
Guest User

PHP- Online Activity

a guest
Aug 29th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <form action="rectangle.php" method="post">
  2. <center>
  3. <br>
  4. <br>
  5. <br>
  6. <h2>Please enter the length and the width of your rectangle.</h2>
  7. // I put placeholder
  8. Enter length: <input type="text" name="textL" placeholder= "Enter number"/>
  9. <br>
  10. <br>
  11. Enter width: <input type="text" name="textW" placeholder= "Enter number"/>
  12. <br>
  13. <br>
  14. <input type="submit" value="Submit" />
  15. </br>
  16. <br>
  17. </form>
  18.  
  19. <?php
  20. if(isset($_POST['textL']) && isset($_POST['textW'])){
  21. if(!empty($_POST['textL']) && !empty($_POST['textW'])){
  22. if(!preg_match("([0-9])",$_POST['textL']) || !preg_match("([0-9])",$_POST['textW'])){
  23. echo 'Enter only numbers.';
  24. }
  25. else{
  26. $l = $_POST['textL'];
  27. $w = $_POST['textW'];
  28. echo "The rectangle with length $l and width $w has an area of ".calculate($l,$w);
  29. }
  30. }
  31. }
  32. // I use function to calculate the length and the width
  33. function calculate($length, $width){
  34. $area = $length * $width;
  35. return $area;
  36. }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement