Code
<!DOCTYPE html> <html> <head> <title>Addition of Numbers Using Forms</title> </head> <body> <?php $value1 = ""; $value2 = ""; $res=""; if (isset($_POST["add"])) { $value1 = $_POST['val_1']; $value2 = $_POST['val_2']; if (is_numeric($value1) && is_numeric($value2)) { $add = ($value1 + $value2); $res = "<h3>The sum of $value1 and $value2 is $add </h3>"; } else { $res = "<h3>The Value is not in Numbers </h3>"; } } if (isset($_POST["clear"])) { $value1 = ""; $value2 = ""; } ?> <h2> Sum of Two Numbers </h2> <form method="POST"> Enter First Value <br /> <input type="text" name="val_1" value="<?php echo "$value1"; ?>" /> <br /> Enter Second Value <br /> <input type="text" name="val_2" value="<?php echo "$value2"; ?>"/> <br> <input type="submit" name="add" value="Add"> <input type="submit" name="clear" value="Clear" /> </form> <?php echo $res; ?> </body> </html>
Output
![Values Not Type](https://www.ahirlabs.com/wp-content/uploads/2017/11/add1.png)
![Addition of two Numbers in PHP Forms](https://www.ahirlabs.com/wp-content/uploads/2017/11/add2.png)
Demo
(Visited 593 times, 1 visits today)
Written by: