-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
question.php
94 lines (86 loc) · 2.91 KB
/
question.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
<?php
session_start();
include "connection.php";
if (isset($_SESSION['id'])) {
if (isset($_GET['n']) && is_numeric($_GET['n'])) {
$qno = $_GET['n'];
if ($qno == 1) {
$_SESSION['quiz'] = 1;
}
}
else {
header('location: question.php?n='.$_SESSION['quiz']);
}
if (isset($_SESSION['quiz']) && $_SESSION['quiz'] == $qno) {
$query = "SELECT * FROM questions WHERE qno = '$qno'" ;
$run = mysqli_query($conn , $query) or die(mysqli_error($conn));
if (mysqli_num_rows($run) > 0) {
$row = mysqli_fetch_array($run);
$qno = $row['qno'];
$question = $row['question'];
$ans1 = $row['ans1'];
$ans2 = $row['ans2'];
$ans3 = $row['ans3'];
$ans4 = $row['ans4'];
$correct_answer = $row['correct_answer'];
$_SESSION['quiz'] = $qno;
$checkqsn = "SELECT * FROM questions" ;
$runcheck = mysqli_query($conn , $checkqsn) or die(mysqli_error($conn));
$countqsn = mysqli_num_rows($runcheck);
$time = time();
$_SESSION['start_time'] = $time;
$allowed_time = $countqsn * 0.05;
$_SESSION['time_up'] = $_SESSION['start_time'] + ($allowed_time * 60) ;
}
else {
echo "<script> alert('something went wrong');
window.location.href = 'home.php'; </script> " ;
}
}
else {
echo "<script> alert('error');
window.location.href = 'home.php'; </script> " ;
}
?>
<?php
$total = "SELECT * FROM questions ";
$run = mysqli_query($conn , $total) or die(mysqli_error($conn));
$totalqn = mysqli_num_rows($run);
?>
<html>
<head>
<title>PHP-kuiz</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<header>
<div class="container">
<h1>PHP-Kuiz</h1>
</div>
</header>
<main>
<div class= "container">
<div class= "current">Question <?php echo $qno; ?> of <?php echo $totalqn; ?></div>
<p class="question"><?php echo $question; ?></p>
<form method="post" action="process.php">
<ul class="choices">
<li><input name="choice" type="radio" value="a" required=""><?php echo $ans1; ?></li>
<li><input name="choice" type="radio" value="b" required=""><?php echo $ans2; ?></li>
<li><input name="choice" type="radio" value="c" required=""><?php echo $ans3; ?></li>
<li><input name="choice" type="radio" value="d" required=""><?php echo $ans4; ?></li>
</ul>
<input type="submit" value="Submit">
<input type="hidden" name="number" value="<?php echo $qno;?>">
<br>
<br>
<a href="results.php" class="start">Stop Kqiz</a>
</form>
</div>
</main>
</body>
</html>
<?php }
else {
header("location: home.php");
}
?>