Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <body background = "a.png">
- <form action="rectanglearea.php" method="post">
- <center>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <br>
- <h3>Please enter the Length and the Width of your rectangle.</h3>
- 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
- <br>
- <br>
- Enter width: <input type="text" name="textW" placeholder= "Enter number"/> //same as length, it's to enter the width.
- <br>
- <br>
- <input type="submit" value="Submit" /> here is to submit the length and width
- <br>
- <br>
- </form>
- <?php
- 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.
- 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.
- if(!preg_match("([0-9])",$_POST['textL']) || !preg_match("([0-9])",$_POST['textW'])){
- echo 'Enter only numbers.';
- }
- else{
- $l = $_POST['textL'];
- $w = $_POST['textW'];
- echo "The rectangle with length $l and width $w has an area of ".calculate($l,$w); //the output of calculation.
- }
- }
- }
- function calculate($length, $width){
- $area = $length * $width; //the calculation of the rectangle area.
- return $area;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement