forked from Junge21/Php-Programming
-
Notifications
You must be signed in to change notification settings - Fork 2
/
calculator.php
64 lines (55 loc) · 1.06 KB
/
calculator.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
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<fieldset>
<legend> Calculator </legend>
<form method="POST" action="calculator.php">
First Number<input type="number" name="First_number"><br>
Second Number<input type="number" name="Second_number"><br>
<select name="option">
<option value="add">add</option>
<option value="sub">sub</option>
<option value="mul">mul</option>
<option value="div">div</option>
</select><br><br>
<input type="submit" name="submit" value="calculate">
</form>
</fieldset>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
if(isset($_POST["submit"]))
{
$num1=$_POST["First_number"];
$num2=$_POST["Second_number"];
$operator=$_POST["option"];
switch ($operator)
{
case 'add':
$add=$num1+$num2;
echo"addition is:".$add;
break;
case 'sub':
$sub=$num1-$num2;
echo"subtraction is:".$sub;
break;
case 'mul':
$mul=$num1*$num2;
echo"mulplication is:".$mul;
break;
case 'div':
$div=$num1/$num2;
echo"division is:".$div;
break;
}
}
?>