PHP Program to find the area of rectangle with form and database

PHP Program to find the area of a rectangle with form and database

In this tutorial, we will learn about the followings.

  1. PHP Program to find the area of rectangle 
  2. PHP Program to find the area of rectangle with form
  3. PHP Program to find the area of rectangle with  database

The logic of the program to find the area of a rectangle.

Area = w × h

w = width
h = height

Suppose 

w = width=5
h = height=10

Area =5*10=50

PHP Program to find the area of a rectangle.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<?php  
 $length = 14;  
 $width = 12;  
 echo "area of rectangle is $length * $width= " . ($length * $width) . "<br />"; 
 echo "perimeter of rectangle is $length * $width= " . (2*($length+$width)) . "<br />"; 
	
  ?>  
</body>
</html>

PHP Program to find the area of a rectangle with form.

<form method="POST">
Enter the length
<input type = "text" name = "le">
<br/>

Enter the breadth
<input type = "text" name = "br">
<br/>

<input type= "submit" value = "submit" name="btnsubmit">
</form>
<?php
if(isset($_POST['btnsubmit']))
{
$l=$_POST['le'];
$b=$_POST['br'];

$area=$l*$b;
$peri= 2*($l+$b);
echo "The aea of rectangle ".$area."<br/>";
echo "The perimeter of rectangle ".$peri."<br/>";
}
?>

PHP Program to find the area of a rectangle with database.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>


<form method="POST">
Enter the length
<input type = "text" name = "le">
<br/>

Enter the breadth
<input type = "text" name = "br">
<br/>

<input type = "submit" name="btnsubmit" value = "submit">
</form>
<?php
	$server = "localhost";
    $user="root";
    $password="";
    $database="RectangleArea";

	$con=mysqli_connect("localhost","root","","RectangleArea");

if(isset($_POST['btnsubmit']))
{	

$l=$_POST['le'];
$b=$_POST['br'];

$area=$l*$b;
$peri= 2*($l+$b);
	  if(isset($_POST['btnsubmit']))
	  {
	  $res= mysqli_query($con,"INSERT INTO rectangle (lenghth,breadth,area ,perimeter ) VALUES ('$l','$b','$area','$peri')");
	  
	  }
echo "The aea of rectangle ".$area."<br/>";
echo "The perimeter of rectangle ".$peri."<br/>";
}
?>

</body>
</html>

 

Database:

rectanglearea program in php database
rectangle area program in php database.
Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.