-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess.php
More file actions
34 lines (33 loc) · 869 Bytes
/
process.php
File metadata and controls
34 lines (33 loc) · 869 Bytes
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
<?php
session_start();
include 'config/config.php';
include 'lib/Database.php';
$db = new Database();
//Get Total no of questions
$query1 = "SELECT * FROM `questions`";
$result = $db->select($query1);
$total = $result->num_rows;
if (!isset($_SESSION['score'])) {
$_SESSION['score'] = 0;
}
if ($_POST) {
$number = $_POST['number'];
$selected_choice = $_POST['choice'];
$next = $number+1;
}
//Get Correct Choice
$query = "SELECT * FROM `choices` WHERE `question_number` = $number AND `is_correct` = 1";
$result = $db->select($query);
$row = $result->fetch_assoc();
$correct_choice = $row['id'];
//Check for correct choice
if($selected_choice == $correct_choice){
$_SESSION['score']++;
}
//Check for question number
if ($number == $total) {
header("Location: final.php");
exit();
} else {
header("Location: questions.php?n=".$next);
}