-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadder.php
More file actions
71 lines (66 loc) · 2.16 KB
/
adder.php
File metadata and controls
71 lines (66 loc) · 2.16 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Adder Assignment</title>
<style>
p {
color: red;
}
.error {
color: red;
font-style: italic;
font-size: .9em;
margin-top: 15px;
}
</style>
</head>
<body>
<form action="" method = "post">
<h1>Adder.php</h1>
<label>Enter the first number:</label>
<input type="number" name="num1"><br>
<label>Enter the second number:</label>
<input type="number" name="num2"><br>
<input type="submit" value="Add Em!!">
</form>
<?php //adder-wrong.php
if (isset($_POST['num1'], $_POST['num2'])){
$num1 = intval($_POST['num1']);
$num2 = intval($_POST['num2']);
$myTotal = $num1 + $num2;
if(empty($_POST['num1'] &&
$_POST['num2'])) {
echo '<p class = "error">Please enter numbers!</p>';
echo '<p><a href = "">Reset page</a></p>';
} else {
echo '<h2>You added '. $num1 .' and '.$num2.'';
echo '<p>and the answer is </p><br> '.$myTotal.'!';
echo '<p><a href = "">Reset page</a></p>';
}
}
?>
</body>
</html>
<!-- NOTE: I initially included line numbers for each error but after much copying & pasting,
the line numbers no longer correlated to the original errors, so I removed them for clarity.
Hope this is OK! -->
<!-- moved php closing tag to end of php code -->
<!-- removed ';{ from end of html closing tag -->
<!-- removed subtraction symbol from equation -->
<!-- replaced capital N with n for variable $num2 -->
<!-- switched double quotes to single quotes for php -->
<!-- added $_POST['num2'] to if statement -->
<!-- moved style tag into correct place-->
<!-- added <!DOCTYPE html> & <html lang="en"> above html head-->
<!-- fixed incorrect closing form tag, added method-->
<!-- moved Adder.php into form tags-->
<!-- added opening label tag -->
<!-- corrected capital N in Num1 on -->
<!-- changed input types to number -->
<!-- added closing label tag, removed closing tag at beginning of phrase-->
<!-- moved closing form tag -->
<!-- added ending quote -->
<!-- moved php into html body-->
<!-- added styles for p & error tags-->
<!-- added intval() function on lines 30 & 31-->
<!-- added if else statement and error message in case no values are entered-->