-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathanswer.php
242 lines (169 loc) · 4.52 KB
/
answer.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
include('inc/header.php');
$_SESSION['userans']= rand(100,10000);
/*
$_SESSION['userans']= rand(10,10000)
This code will generate a random value for users ans for particular category so we can easyly retrive users value for particular session
it genrates random value of seeion in DB when we want to retrive data so we will call this session varabile so we can reteive data for particular session.
*/
//print_r($_POST);
//die;
foreach ($_POST as $que => $answers)
{
/*echo "<br>";
echo $que;
echo "<br>";
echo $answers;
echo "<pre>";
print_r($que);
echo"-->";
print_r($answers);
echo "</pre>";
*/
/*
==============================================================
Query for storeing users answer in our table so we can further retrive or match with ans with users ans
================================================================ */
//print_r($que);
//print_r($answers);
//die;
$insert_ans="INSERT INTO user_ans_details(name,question_id,answer,category_id,session,date)VALUES('".$_SESSION['fname']."','$que','$answers','".$_SESSION['cat']."','".$_SESSION['userans']."',CURRENT_TIMESTAMP)";
$user_result=mysqli_query($conn,$insert_ans);
if($user_result!=true){
die('failed to insert');
}
else{
//echo"inserted";
}
}
//print_r($_POST);
//die;
//die;
include('inc/connection.php');
$category=$_SESSION['cat'];
/*
echo"<pre>";
print_r($_POST);
echo"</pre>";
*/
$right=0;
echo "<br>";
$wrong=0;
echo "<br>";
$no_answer=0;
//die;
$chk_ans="select id,ans from questions where category_id='".$_SESSION['cat']."' ";
$res=mysqli_query($conn,$chk_ans);
if(mysqli_num_rows($res)>0){
while($rs=mysqli_fetch_assoc($res))
{
/*print_r($rs['ans']);
echo "<br>";
echo"<pre>";
print_r($_POST[$rs['id']]);
echo"</pre>";
*/
if($rs['ans']==$_POST[$rs['id']])
{
echo "<br>";
$right++;
}
elseif($_POST[$rs['id']]=="no_answer")
{
$no_answer++;
}
else
{
$wrong++;
}
//die;
}
$array=array();
$array['right']=$right;
$array['wrong']=$wrong;
$array['no_answer']=$no_answer;
echo"<br>";
/*echo "<pre>";
print_r($array['right']);
echo "</pre><br>===========================";
echo "<pre>";
print_r($array['wrong']);
echo "</pre><br>===========================";
print_r($array['no_answer']);
*/
$_SESSION['Right']=$array['right'];
$_SESSION['Wrong']=$array['wrong'];
$_SESSION['NoANS']=$array['no_answer'];
//print_r($_SESSION['Right']);
//print_r($_SESSION['Wrong']);
//print_r($_SESSION['NoANS']);
$total = $right + $wrong + $no_answer;
$per=($right*100)/($total);
$per."%";
/*
echo 'RightAns'. " ".$right;
echo '<br>'.$wrong;
echo '<br>'.$no_answer;
*/
}
if (!isset($_SERVER['HTTP_REFERER'])){
// echo "<script>alert('hii')</script>";
header("location:home.php");
}
?>
<style type="text/css">
body {
background: #34495e;
/*color: #ecf0f1;*/
margin: 0;
padding: 0;
}
td,h3{
color: #ecf0f1;
}
</style>
<div class="container">
<center><h3><?php echo $_SESSION['fname']; ?></h3>
<hr>
<table border="1" class="table table-striped">
<tr>
<th>sno<?php $counter=1;?></th>
<th>Total</th>
<th>Right</th>
<th>Wrong</th>
<th>Not Attempt</th>
<th>PERCENTAGE</th>
<th>STATUS</th>
</tr>
<tr>
<td><?php echo $counter++ ;?></td>
<td><?php echo $total;?></td>
<td><?php echo $right; ?></td>
<td><?php echo $wrong; ?></td>
<td><?php echo $no_answer; ?></td>
<td><?php echo $per."%";?></td>
<td>
<?php
if($per<33){
echo"FAIL";
}
else{
echo"PASS";
}
?></td>
</tr>
</table>
</center>
<?php
$insert_res="INSERT INTO result(name,category,total_questions,right_ans,wrong_ans,not_attempt,percentage,
status,date) VALUES('".$_SESSION['fname']."','$category','$total','$right','$wrong','$no_answer','$per','status',CURDATE())";
$result=mysqli_query($conn,$insert_res);
if($result!=true){
die('failed to insert');
}
else{
//echo "INSERTED SUCCESSFULLY";
}
?>
<center><a href="user_answer.php" class="btn btn-primary">Check Your Answers</a></center>
</div>