forked from VaibhavD143/Quiz-Portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax_handler.php
31 lines (27 loc) · 1 KB
/
ajax_handler.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
<?php
if(isset($_POST['action'])){
if(strcmp($_POST['action'], "quiz_start")==0){
require_once('connection.php');
$query = $database_handler->prepare("UPDATE user SET time_started = ? WHERE user_id = ?;");
$query->bind_param('ii', $_POST['time_started'], $_COOKIE['user_id']);
$query->execute();
echo "Quiz Started";
}
}
else{
require_once('connection.php');
$sql = "INSERT INTO answer (user_id, ques_id, answer_provided) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE answer_provided = ?;";
$query = $database_handler->prepare($sql);
$user_id = (int)$_COOKIE['user_id'];
foreach($_POST as $ques_id => $ans){
$query->bind_param('iiss', $user_id, $ques_id, $ans, $ans);
$query->execute();
echo $ques_id . ' '. $ans;
}
$time_elapsed = $_COOKIE['time_elapsed'];
$query = $database_handler->prepare("UPDATE user SET time_elapsed=? WHERE user_id = ?;");
$query->bind_param('ii', $time_elapsed, $user_id);
$query->execute();
echo "Quiz Started";
}
?>