In this program, you’ll learn to store and add two numbers in PHP. After addition, the final sum is displayed on the screen.
Output: Here is the output of adding Two Textbox Values and Display the Sum
PHP Code: In this program code you can see how to add two numbers in php using html
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 | <?php $num1=0; $num2=0; $sum=0; if(isset($_POST["add"])) { $num1=$_POST["num1"]; $num2=$_POST["num2"]; $sum=$num1+$num2; } ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Add 2 Numbers in PHP</title> <style> label{ display: block; } </style> </head> <body> <h1>Sum of Two Numbers:<?=$sum?></h1> <form method="post"> <label>Number 1: <input type="text" name="num1" value="<?=$num1?>"> </label> <label>Number 2: <input type="text" name="num2" value="<?=$num2?>"> </label> <button type="submit" name="add">Add Numbers</button> </form> </body> </html> |