-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion3.php
More file actions
61 lines (55 loc) · 1.64 KB
/
question3.php
File metadata and controls
61 lines (55 loc) · 1.64 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
<!DOCTYPE HTML>
<html>
<head>
<title>
Question 3
</title>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<?php
// define variables and set to empty values
$optionErr = "";
$option = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["option"])) {
$optionErr = "Answer is required";
} else {
$option = test_input($_POST["option"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>Question 3</h2>
<p><span class="error">* required field</span></p>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Options: <br>
<input type="radio" name="option" <?php if (isset($option) && $option=="option1") echo "checked";?> value="option1">option1 <br>
<input type="radio" name="option" <?php if (isset($option) && $option=="option2") echo "checked";?> value="option2">option2 <br>
<input type="radio" name="option" <?php if (isset($option) && $option=="option3") echo "checked";?> value="option3">option3 <br>
<input type="radio" name="option" <?php if (isset($option) && $option=="option4") echo "checked";?> value="option3">option4 <br>
<span class="error">* <?php echo $optionErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
<?php
echo "<h2>Your Input:</h2>";
echo "<br>";
if($option== "option1"){
echo $option;
echo "<br>";
echo "Awesome it's correct! you will be redirected to next page in 5 seconds!";
header( "refresh:5;url=question4.php" );
}
else
echo"Wrong answer!"
?>
</body>
</html>