Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form action="rectangle.php" method="post">
- <center>
- <br>
- <br>
- <br>
- <h2>Please enter the length and the width of your rectangle.</h2>
- // I put placeholder
- Enter length: <input type="text" name="textL" placeholder= "Enter number"/>
- <br>
- <br>
- Enter width: <input type="text" name="textW" placeholder= "Enter number"/>
- <br>
- <br>
- <input type="submit" value="Submit" />
- </br>
- <br>
- </form>
- <?php
- if(isset($_POST['textL']) && isset($_POST['textW'])){
- if(!empty($_POST['textL']) && !empty($_POST['textW'])){
- 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);
- }
- }
- }
- // I use function to calculate the length and the width
- function calculate($length, $width){
- $area = $length * $width;
- return $area;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement