-
Notifications
You must be signed in to change notification settings - Fork 0
/
verification_answer.php
38 lines (28 loc) · 1.07 KB
/
verification_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
<?php
include 'config/db.php';
session_start();
$option_id = $_POST["option_id"];
$question_id = $_POST["question_id"];
$sql = "SELECT answer FROM options WHERE id = " . $option_id . " and question_id = " . $question_id;
$consult = $con->prepare($sql);
$consult->execute();
$question = $consult->fetch();
unset($_SESSION["lastQuestion"]);
if($question["answer"]){
$_SESSION["current_score"]++;
$questions = $_SESSION["current_questions"];
array_push($questions,$question_id);
$_SESSION["current_questions"] = $questions;
if ($_SESSION["current_score"]>$_SESSION["score"]) {
$_SESSION["score"] = $_SESSION["current_score"];
$sql = "UPDATE users SET score= " . $_SESSION["score"] . " WHERE email=" . "'". $_SESSION["email"] ."'";
$consult = $con->prepare($sql);
$consult->execute();
}
http_response_code(200);
}else{
$_SESSION["current_questions"] = [];
$_SESSION["current_score"] = 0;
http_response_code(503);
}
?>