-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
54 lines (52 loc) · 1.61 KB
/
index.php
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
<!DOCTYPE html>
<html>
<head>
<title>Eenvoudige Rekenmachine</title>
</head>
<body>
<h1>Eenvoudige Rekenmachine</h1>
<form method="post" action="">
Nummer 1: <input type="text" name="num1"><br>
Nummer 2: <input type="text" name="num2"><br>
Bewerking:
<select name="operation">
<option value="add">Optellen</option>
<option value="subtract">Aftrekken</option>
<option value="multiply">Vermenigvuldigen</option>
<option value="divide">Delen</option>
</select><br><br>
<input type="submit" name="submit" value="Bereken">
</form>
<?php
if (isset($_POST['submit'])) {
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$operation = $_POST['operation'];
$result = 0;
if (is_numeric($num1) && is_numeric($num2)) {
switch ($operation) {
case "add":
$result = $num1 + $num2;
break;
case "subtract":
$result = $num1 - $num2;
break;
case "multiply":
$result = $num1 * $num2;
break;
case "divide":
if ($num2 != 0) {
$result = $num1 / $num2;
} else {
$result = "Fout: Delen door nul.";
}
break;
}
echo "<h2>Resultaat: $result</h2>";
} else {
echo "<h2>Voer alstublieft geldige nummers in.</h2>";
}
}
?>
</body>
</html>