-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.php
More file actions
73 lines (66 loc) · 2 KB
/
main.php
File metadata and controls
73 lines (66 loc) · 2 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php require_once(__DIR__.'/Math/Index.php');
$result = '0';
if(isset($_POST['a']) && isset($_POST['b']) && isset($_POST['process'])) {
$math = new \Math\Index;
switch(strtolower($_POST['process'])) {
case 'add':
try {
$result = $math->setA($_POST['a'])
->setB($_POST['b'])
->add();
} catch(Exception $e) {
$msg = $e->getMessage();
}
break;
case 'subtract':
try {
$result = $math->setA($_POST['a'])
->setB($_POST['b'])
->subtract();
} catch(Exception $e) {
$msg = $e->getMessage();
}
break;
case 'multiply':
try {
$result = $math->setA($_POST['a'])
->setB($_POST['b'])
->multiply();
} catch (Exception $e) {
$msg = $e->getMessage();
}
break;
case 'divide':
try {
$result = $math->setA($_POST['a'])
->setB($_POST['b'])
->divide();
} catch(Exception $e) {
$msg = $e->getMessage();
}
break;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h4 id="title">Test 123</h4>
<?php if(isset($msg)): ?>
<p><?php echo $msg; ?></p>
<?php endif; ?>
<form method="post">
<p><input type="text" id="a" name="a" /></p>
<p><input type="text" id="b" name="b" /></p>
<p>
<input type="submit" name="process" value="Add" id="add" />
<input type="submit" name="process" value="Subtract" id="subtract" />
<input type="submit" name="process" value="Multiply" id="multiply" />
<input type="submit" name="process" value="Divide" id="divide" />
</p>
</form>
<div id="result"><?php echo $result; ?></div>
</body>
</html>