-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.php
32 lines (26 loc) · 946 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
<?php include 'database.php'; ?>
<?php session_start(); ?>
<?php
if(!isset($_SESSION['score']))
$_SESSION['score'] = 0;
if($_POST) {
$number = $_POST['number'];
$selected_choice = $_POST['choice'];
$query = "select * from questions";
$results = $mysqli->query($query) or die($mysqli->error.__LINE__);
$total = $results->num_rows;
$query = "select * from choices where
question_number = $number and
is_correct = 1";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$row = $result->fetch_assoc();
$correct_choice = $row['id'];
$next = ++$number;
if($selected_choice == $correct_choice) {
$_SESSION['score']++;
}
if($number == $total+1)
header("Location: final.php");
else
header("Location: question.php?n=".$next);
}