In: Computer Science
Write a PHP program using HTML form. It will take Length, Width and Height of a box as input. When a button is pressed, it will calculate the Volume. If Volume is less than 25 then display the message “Small box”. If Volume is from 25 to 50, it will display the message “Medium box”. When the Volume is greater than 50, then display the message “Large box”.
index.html file :-
<html>
<center>
<body>
<form action="index.php" method="post">
<label
for="Length"><b>Length</b></label>
<input type="text" placeholder="Length" name="Length"
required><br><br>
<label
for="Width"><b>Width</b></label>
<input type="text" placeholder="Width" name="Width"
required><br><br>
<label
for="Height"><b>Height</b></label>
<input type="text" placeholder="Height" name="Height"
required><br><br>
<input type="submit" value="submit">
</form>
</body>
</center>
</html>
index.php file :-
<html>
<body>
<center>
<?php
if(isset($_POST['Length']) && isset($_POST['Width'])
&& isset($_POST['Height']))
{
$length = $_POST['Length'];
$width = $_POST['Width'];
$height = $_POST['Height'];
$volume = $length * $width * $height;
if ($volume<25)
{
echo "Small
box";
}
elseif ($volume>=25 &&
$volume<=50)
{
echo "Medium
box";
}
elseif ($volume>50)
{
echo "Large box";
}
}
?>
</center>
</body>
</html>
Sreenshot of file and output:-