# How can I found area of rectangle using PHP, HTML form and result in text box?

248 views
I want to create and HTML form with PHP functionality. I want to find out the area of the rectangle using HTML form and PHP. The result should be displayed in another text box.

I explain -

I want to create and HTML form text boxes to insert the values and result in the third input box (text box) using PHP.
in PHP

+1 vote

Yes , It is possible to insert the value in the input box and result in another text box. You can use the HTML form and a PHP script to find out the area of the rectangle on the button click. First of all, you need to know the mathematical formula for the area of the rectangle .  The mathematic formula for the area of rectangle is A = wl.

A = A denotes the area of the rectangle.

w= w denotes the width of the rectangle.

l = l is the length of the rectangle.

We can write this formula in PHP. like =  a=w*l ;

You can see the w and l will be entered by the user. We create three text boxes in HTML. The two text boxes are for l and w and one text box for the result.

When a user enter the l and w of the rectangle , the result displays in the third text box.

Let's create an HTML form.

<html>

<body>

<form action="" method="post">

Width :

<input type="text" name="w"><br>

Length :

<input type="text" name="l"><br>

<input type="submit" name="submit" value="area"><br>

</form>

</body>

</html>

We created an HTML form with two input boxes and one button. Now create the PHP script to get the area of the rectangle in the third text box.

<?php

\$a="";

if(isset(\$_POST['submit']))

{

\$w=\$_POST['w'];

\$l=\$_POST['l'];

\$a=\$w*\$l;

}

?>

Result:<input type="text" value="<?php echo \$a; ?>">

Now add this PHP code in a single file and execute.

<html>

<body>

<form action="" method="post">

Width :

<input type="text" name="w"><br>

Length :

<input type="text" name="l"><br>

<input type="submit" name="submit" value="area"><br>

</form>

</body>

</html>

<?php

\$a="";

if(isset(\$_POST['submit']))

{

\$w=\$_POST['w'];

\$l=\$_POST['l'];

\$a=\$w*\$l;

}

?>

Result:<input type="text" value="<?php echo \$a;?>">

Enter the width and length of rectangle in text boxes, you will get the result into the third text box.

by (9.1k points) 11 25 63
edited by

You can find out the area of the rectangle after creating an HTML form and PHP script. That's really good to find out the area of the rectangle using the PHP script. Let's think about it.

Create an HTML form with three input boxes-

Input box 1-

input box - 2

input box 3 .

The text box 1 and the text box 2 are for the insert the value and the third text box will be used to display the result.

<html>

<body>

<input type="text" name="w">

<input type="text" name="l">

<input type="submit" name="submit">

</body>

<html>

You should understand the PHP script . Th area of the rectangle is A=wl .

I have a reference for you.

by (7.2k points) 13 29 62