PHP Program - Add two Numbers

We have created below PHP Program to add two Numbers. HTML <form> tag with post method is used to submit two numbers.

<input type="submit" value="Add" name="submit" /> html tag is used to submit html form.

<input type="text" name="num1" required> and <input type="text" name="num2" required> are used to enter numbers for getting answer of addition.

$_POST variable is used to retrive 2 numbers for performing addition .

Example :

<?php
if(isset($_POST['submit']))
{
$num1=$_POST['num1'];
$num2=$_POST['num2'];
$result=$num1+$num2;
echo "<b>Addition of " .$num1. " and ".$num2. " :</b> " .$result;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>PHP Program - Add two number by aryatechno</title>
</head>
<body>
<table>
<form name="sum" method="post">
<tr>
<td>Number 1 :</td>
<td><input type="text" name="num1" required></td>
</tr>
<tr>
<td>Number 2 :</td>
<td><input type="text" name="num2" required></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Add" name="submit" /></td>
</tr>
</form>
</table>
</body>
</html>

Output :

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

51599