forked from cse442-at-ub/s24semesterproject-interns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion1.php
140 lines (132 loc) · 4.42 KB
/
question1.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Q1</title>
<link rel="stylesheet" href="css/style.css" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<header>
<div class="container">
<h1>Question 1</h1>
</div>
</header>
<style>
body {
font-family: 'Times New Roman', Times, serif, sans-serif;
margin: 0;
padding: 0;
font-size: 20px;
background-color: #C3B1E1;
}
.container {
max-width: 600px;
margin: 50px auto;
padding: 20px;
background-color: #CCCCFF;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1, h2 {
text-align: center;
}
.question {
margin-bottom: 20px;
}
.answer-box {
width: 101075%;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
.button-group {
text-align: center;
}
.button-group button {
padding: 10px 20px;
margin: 0 10px;
font-size: 16px;
border: none;
border-radius: 5px;
cursor: pointer;
}
.button-group button.active {
background-color: #4CAF50;
color: white;
}
.next-button {
margin-top: 20px;
background-color: #C3B1E1;
color: white;
}
</style>
<?php
//$dbname = "cse442_2024_spring_team_f_db";
//$dbname = "interns_cse442";
$dbname = "my442db";
$conn = new mysqli("", "root", "", $dbname);
$current = "SELECT data_percent FROM mydb";
$value = $conn->query($current);
$yes = 0;
$no = 0;
$sum = 0;
if ($value->num_rows > 0){
while($row = $value->fetch_assoc()){
$dict = json_decode($row["data_percent"],true);
$yes = $dict["yes"];
$no = $dict["no"];
}
}
$sum = $yes + $no;
if ($sum == 0){
$html_yes = "0%";
$html_no = "0%";
}else{
$html_yes = strval(round(($yes/$sum)*100, 2) . '%');
$html_no = strval(round(($no/$sum)*100, 2) . '%');
}
//session_start();$_SESSION['back_1'] = False;$_SESSION['question1'] = False;
?>
<main>
<div class="container">
<form method="post" action="back.php">
<input class="next-button" type="submit" name="back1"value="BACK">
</form>
<form method="post" action="quizpage.php">
<p class="question">
<label>Do you like alcohol?</label>
</p>
<div class="choices">
<input name="alcohol_choice" type="radio" value="Yes">
<label for="Yes">Yes<br><?php echo "Selected percentage: $html_yes<br>";?></label>
<input name="alcohol_choice" type="radio" value="No">
<label for="No">No<br><?php echo "Selected percentage: $html_no<br>";?></label>
</div>
<button class="next-button" id="next">NEXT</button>
<script>
// Get the button element
var button = document.getElementById("next");
// Add a click event listener to the button
button.addEventListener("click", function() {
var alcoholChoice = document.querySelector('input[name="alcohol_choice"]:checked');
if (!alcoholChoice) {
//window.location.replace("question1.php");
alert("You have not selected any options yet!");
<?php session_start();$_SESSION['question1'] = False;?>
}
});
</script>
</form>
</div>
</main>
<footer>
<div class="container">
Interns ©2024, Quiz
</div>
</footer>
</body>
</html>