I am going to describe here how to add two numbers using PHP. For this you should have  little bit knowledge of PHP and Jquery. Do following steps:

  1. Create a php page sum.php
  2. You need to make html form
  3. Add jquery library file on the top of the page

Complete code is below:

<script src=”https://code.jquery.com/jquery-1.11.3.js”></script>
<script>
$(document).ready(function(){
$(“#Save”).click(function(){
var num1 = $(“#first”).val();
var num2 = $(“#second”).val();
$.ajax({
type:”POST”,
url:”process.php”,
data:”num1=”+num1+”&num2=”+num2,
success:function(data){
$(“h2″).text(data);
}
})
})
})
</script>

<table width=”50%” border=”0″>
<tr>
<td>First</td>
<td><input type=”number” id=”first”></td>
</tr>
<tr>
<td>Second</td>
<td><input type=”number” id=”second”></td>
</tr>
<tr>
<td></td>
<td><input type=”button” id=”Save” value=”Submit”></td>
</tr>
</table>
<h2></h2>

 

4. Now create a php page for processing name as process.php

5. write the php code for adding two numbers as below

Code is:

<?php
if(isset($_POST[‘num1’]) && $_POST[‘num2’]){
echo $_POST[‘num1’] + $_POST[‘num2’];
}
?>

6. Now run your file and see the result