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
Values Not Type
Addition of two Numbers in PHP Forms
Addition of two Numbers in PHP Forms

Demo

 

(Visited 548 times, 1 visits today)
Share with Friends :
Written by:

Leave a Reply

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