<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$leftOperand = $_POST['leftOperand'];
$rightOperand = $_POST['rightOperand'];
$result = " ";
if (isset($leftOperand) && isset($rightOperand)) {
if (isset($_POST['plus'])) {
$result = $leftOperand + $rightOperand;
} elseif(isset($_POST['minus'])) {
$result = $leftOperand - $rightOperand;
} elseif (isset($_POST['multiply'])){
$result = $leftOperand * $rightOperand;
} elseif (isset($_POST['division'])){
if ($rightOperand != '0') {
$result = $leftOperand / $rightOperand;
} else $result = "На ноль делить нельзя!";
}
}
}
?>
<html>
<head>
<title>Homework 4</title>
</head>
<body>
<form method="post">
<input type="text" name="leftOperand" value="<? echo $leftOperand ?>">
<input type="text" name="rightOperand" value="<? echo $rightOperand ?>">
<?php
echo ' = ';
echo $result;
?><br>
<input type="submit" name="plus" value="+">
<input type="submit" name="minus" value="-">
<input type="submit" name="multiply" value="*">
<input type="submit" name="division" value="/">
</form>
</body>
</html>