The HTML form is used to add two input box number and sum in the third box using PHP. Here, the sum of two numbers and result in the third text box in PHP. It is very easy to add two number and the showing result in the third box. PHP tutorials for beginners help you understand the complete concept regarding adding two input values and sum in the third box.
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
<?php $sum=""; $number1=""; $number2=""; if(!empty($_POST)) { //get data from inputs $number1=$_POST["number1"]; $number2=$_POST["number2"]; $sum=$number1+$number2; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Code4Example</title> <style> label{ display:block; } </style> </head> <body> <form action="" method="post"> <label for=""> Number 1: <input type="text" name="number1" value="<?=$number1?>"> </label> <label for=""> Number 2: <input type="text" name="number2" value="<?=$number2?>"> </label> <label for=""> Result: <input type="text" name="sum" value="<?=$sum?>"> </label> <button type="submit">Store in Database</button> </form> </body> </html> |
Output: