<!DOCTYPE html>
<html>
<head>
<title>PHP Arithmetic Operations</title>
</head>
<body>
<h2>Enter Two Numbers</h2>
<form method=”post”>
Number 1: <input type=”number” name=”num1″ required><br><br>
Number 2: <input type=”number” name=”num2″ required><br><br>
<input type=”submit” value=”Calculate”>
</form>
<?php
if ($_SERVER[“REQUEST_METHOD”] == “POST”) {
// Take input values
$num1 = $_POST[‘num1’];
$num2 = $_POST[‘num2’];
// Perform operations
$sum = $num1 + $num2;
$sub = $num1 – $num2;
$mul = $num1 * $num2;
$div = ($num2 != 0) ? $num1 / $num2 : “Cannot divide by zero”;
$exp = $num1 ** $num2;
// Display results
echo “<h3>Results:</h3>”;
echo “Sum: $sum <br>”;
echo “Subtraction: $sub <br>”;
echo “Multiplication: $mul <br>”;
echo “Division: $div <br>”;
echo “Exponent (num1 ^ num2): $exp <br>”;
}
?>
</body>
</html>
Take values from the user and compute sum, subtraction, multiplication,
division and exponent of value of the variables.
Output
