PHP: Add two input box values and sum in third box:-

Techno PHP

Sum of two variables is very easy to work but if we want to add two input box values and show the sum value in the third box it will be small difficult.

First of all, we will create an HTML form. In the HTML form , we will create two input box first input box for first input value and the second input box for second input value and will create a submit button. Whenever we will click on submit button the sum of values will print(display) in the third input box.

The simple HTML form .

HTML Code

<html>
<body>
<form action="" method="post">
First Value:

Second Value :

</form> </body> </html>

Now we will create a PHP script for sum of two values and will get a result in third box .

PHP code

<?php
$sum="";
if(isset($_POST['submit']))
{
	$no1=$_POST['no1'];
	$no2=$_POST['no2'];
	$sum=$no1+$no2;
	
		
}
Result:	
?>

Now this time to implementation . The file executed code is here .

Final Code

<html>
<body>
<form action="" method="post">
First Value:

Second Value :

</form> </body> </html> <?php $sum=""; if(isset($_POST['submit'])) { $no1=$_POST['no1']; $no2=$_POST['no2']; $sum=$no1+$no2; } ?> Result:
Run

Related