-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.php
39 lines (32 loc) · 956 Bytes
/
process.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
<?php include 'database.php'; ?>
<?php session_start(); ?>
<?php
//Get no. of the question
$qno = $_POST['qno'];
if (!isset($_SESSION['score']) || $qno == 1) {
$_SESSION['score'] = 0;
}
//Get ID of the choice
$choice_id = $_POST['choice'];
/*
* Get the choice
*/
$query = "SELECT * FROM `choices` WHERE id=$choice_id";
//Fetch the results
$res = $mysqli->query($query) or die ($mysqli->error.__LINE__);
$choice = $res->fetch_assoc();
/*
* BAD PRACTICE ! Getting total no. of questions
*/
$q_count = $mysqli->query("SELECT * FROM `questions`")->num_rows or die ($mysqli->error.__LINE__);
//Add is_correct to the score
$_SESSION['score'] += (int) $choice['is_correct'];
//Redirecting
if ($qno == $q_count) {
header("Location: final.php");
exit();
} else {
$qno++;
header("Location: question.php?n=$qno");
}
?>