Site icon T4Tutorials.com

Addition of the Feet and Inches program in PHP MySQL

Addition of the Feet and Inches program in PHP MySQL

In this tutorial, we will cover the following questions;

  1. Addition of the Feet and Inches program 
  2. Addition of the Feet and Inches program with a form
  3. Addition of the Feet and Inches program in PHP MySQL

Addition of the Feet and Inches program 

<html>
<body>
<?php
$feet=9;
$inch=11;
$feet1=4;
$inch1=7;
$sum=$inch +$inch1;
$x=0;
if($sum >11)
{

$x=intval($sum/12);
$y=$sum%12;
$sum1=$feet +$feet1 +$x;
echo "Feet = $sum1 and Inches = $y";
}
else {
$sum1=$feet +$feet1;

echo "Feet = $sum1 and Inches = $sum";
}
?>
</body>
</html>

Addition of the Feet and Inches program with a form

<html>
<body>
<h1>Assignment 4</h1>
<h2> Addition of Feet and Inches</h2>
<form method="post">
Enter Feet<br><input type="text" name="feet1"><br><br>
Enter Inches<br><input type="text" name="inch1"><br><br>
Enter Feet<br><input type="text" name="feet2"><br><br>
Enter inches<br><input type="text" name="inch2"><br><br>
<input type="submit" name="submit">

<?php
if(isset($_POST['submit'])){

$feet=$_POST['feet1'];
$inch=$_POST['inch1'];
$feet1=$_POST['feet2'];
$inch1=$_POST['inch2'];
$sum=$inch +$inch1;
$x=0;
if($sum >11)
{

$x=intval($sum/12);
$y=$sum%12;
$sum1=$feet +$feet1 +$x;
echo "Feet = $sum1 and Inches = $y";
}
else {
$sum1=$feet +$feet1;

echo "Feet = $sum1 and Inches = $sum";
}}
?>
</body>
</html>

Addition of the Feet and Inches program in PHP MySQL

<html>
<head>
<style>
div {
	
border: solid black;
background-color:#00FF33;
align:center;
	width:600px;
	height:400px;
padding: 20px;
}
</style>
</head>
<body>
<div>

<h2> Addition of Feet and Inches</h2>
<form method="post">
Enter Feet<input type="text" name="feet1">
Enter Inches<input type="text" name="inch1"><br><br>
Enter Feet<input type="text" name="feet2">
Enter inches<input type="text" name="inch2"><br><br>
<input type="submit" name="submit">
<?php
$con=mysqli_connect("localhost","root","","add");
if(isset($_POST['submit'])){

$feet=$_POST['feet1'];
$inch=$_POST['inch1'];
$feet1=$_POST['feet2'];
$inch1=$_POST['inch2'];
$sum=$inch +$inch1;
$x=0;
if($sum >11)
{

$x=intval($sum/12);
$sum=$sum%12;
$sum1=$feet +$feet1 +$x;
echo "Feet = $sum1 and Inches = $sum";
}
else {
$sum1=$feet +$feet1;

echo "Feet = $sum1 and Inches = $sum";
}
$sql= mysqli_query($con,"insert into adds(feet,inches) values('$sum1','$sum')");
}
?>
</div>
</body>
</html>
Figure: Addition of the Feet and Inches program in PHP MySQL
Exit mobile version