-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_response.php
executable file
·84 lines (62 loc) · 2.17 KB
/
save_response.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
session_start();
require_once('dbconfig.php');
// $obj = $_POST['userid'];
$lang = $_SESSION['lang'];
$test = $_SESSION['test'];
$medium = $_SESSION["medium"];
$id = $_SESSION['usersession'];
$_SESSION['userid'] = $id;
$question_id = $_POST["question_id"];
$question = $_POST["question"];
$option = $_POST["option"];
$new_audio = $_POST["filename"];
$obj_marks = $_POST["obj_marks"];
echo ($question);
error_log("RECEIVED : " . $id . $test . $question_id . $lang . $question . $option);
// $gender = $obj["audio_url"];
$testtitle = $lang . ' ' . $test . ' ' .$medium ;
$res2 = mysqli_query($conn, "SELECT answer, option1, option2, option3, option4, option5, marks, q_type FROM `$testtitle` where q_id = '$question_id' ");
if (mysqli_num_rows($res2) > 0) {
$row = mysqli_fetch_array($res2);
$marks = 0;
if($row[0] != ""){
error_log($row[0]);
$correct_ans = "";
if ($row[0] == "A")
$correct_ans = $row[1];
if ($row[0] == "B")
$correct_ans = $row[2];
if ($row[0] == "C")
$correct_ans = $row[3];
if ($row[0] == "D")
$correct_ans = $row[4];
if ($row[0] == "E")
$correct_ans = $row[5];
if ($correct_ans == $option)
$marks = $row[6];
}
}
$res3 = mysqli_query($conn, "SELECT audio FROM result WHERE user_id = '$id' AND q_id = '$question_id'");
if (mysqli_num_rows($res3) > 0) {
$old_audio = mysqli_fetch_array($res3);
error_log($old_audio[0]);
$audio = $old_audio[0].",". $new_audio;
error_log($audio);
}else{
$audio = $new_audio;
}
if( isset($_POST["status"]) )
{
$status = $_POST["status"];
$sql = "UPDATE result SET ans_status = '$status' where q_id = '$question_id' AND user_id = '$id' ";
}else{
$sql = "INSERT INTO result (user_id, lang, test, medium, q_id, answer, audio, ans_status, marks ) VALUES('$id', '$lang', '$test', '$medium', '$question_id', '$option', '$audio', 'attempted', '$marks')
ON DUPLICATE KEY UPDATE answer = '$option', audio = '$audio', marks = '$marks', ans_status = 'attempted' ";
}
if (mysqli_query($conn, $sql)) {
error_log("New record created successfully");
} else {
error_log( "Error: " . mysqli_error($conn));
}
?>