-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assignment1.php
40 lines (28 loc) · 934 Bytes
/
Assignment1.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
<?php
$number1 = 0;
$number2 = 0;
$result = "";
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if (!empty($_POST["number1"])) {
$number1 = test_input($_POST["number1"]);
}
if (!empty($_POST["number2"])) {
$number2 = test_input($_POST["number2"]);
}
$result = $number1 + $number2;
}
?>
<h2> PHP Calculator </h2>
Trevor Herring <p></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Number 1: <input type="text" name="number1" value="<?php echo $number1; ?>"> <p></p>
Number 2: <input type="text" name="number2" value="<?php echo $number2; ?>"> <p></p>
Answer: <input type="text" name="result" value="<?php echo $result; ?>"> <p></p>
<input type="submit" value="Calculate Answer"> <p></p>
</form>