php if _SERVER REQUEST_METHOD POST leftOperand _POST leftOperand right

 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
42
43
<?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>