-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdlv1_submit.php
More file actions
92 lines (78 loc) · 2.57 KB
/
hdlv1_submit.php
File metadata and controls
92 lines (78 loc) · 2.57 KB
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
85
86
87
88
89
90
91
92
<?php
session_start();
$score = 0;
//1_q
if (isset($_POST['1_q'])) {
if ($_POST['1_q'] === "A") {
$_SESSION['1_q'] = "Correct answer!";
$score = $score + 10;
} else {
$_SESSION['1_q'] = "Wrong answer!";
}
} else {
$_SESSION['1_q'] = "Answer is missing!";
}
if (isset($_POST['2_q_1']) || isset($_POST['2_q_2']) || isset($_POST['2_q_3'])
|| isset($_POST['2_q_4']) || isset($_POST['2_q_5'])) {
if (isset($_POST['2_q_1']) && isset($_POST['2_q_2']) && isset($_POST['2_q_3']) && !isset($_POST['2_q_4'])
&& !isset($_POST['2_q_5'])) {
$_SESSION['2_q'] = "Correct Answer!";
$score = $score +10;
} else {
$_SESSION['2_q'] = "Wrong Answer!";
}
} else {
$_SESSION['2_q'] = "Answer is missing!";
}
//3_q
if (isset($_POST['3_q'])) {
if ($_POST['3_q'] === "A") {
$_SESSION['3_q'] = "Correct answer!";
$score = $score + 10;
} else {
$_SESSION['3_q'] = "Wrong answer!";
}
} else {
$_SESSION['3_q'] = "Answer is missing!";
}
//4_q
if (isset($_POST['4_q'])) {
if ($_POST['4_q'] === "B") {
$_SESSION['4_q'] = "Correct answer!";
$score = $score + 10;
} else {
$_SESSION['4_q'] = "Wrong answer!";
}
} else {
$_SESSION['4_q'] = "Answer is missing!";
}
//5_q
if (!empty($_POST['5_q_1']) && !empty($_POST['5_q_2'])) {
if ($_POST['5_q_1'] == "seasonal" && $_POST['5_q_2'] =="affective") {
$_SESSION['5_q'] = "Correct answer!";
$score += 10;
} else {
$_SESSION['5_q'] = "Wrong answer!";
}
} else {
$_SESSION['5_q'] = "Answer is missing!";
}
$_SESSION['hd_lv1_score'] = $score;
//db connection
$dbLocalhost = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
mysql_select_db("healthquizup", $dbLocalhost) or die("Could not find database: " . mysql_error());
$dbRecords = mysql_query("SELECT * FROM wp_hdquizscore
WHERE ID ='" . $_SESSION['user_id'] . "'", $dbLocalhost) or die("Problem reading table: " . mysql_error());
if ($arrRecords = mysql_fetch_assoc($dbRecords)){
if ($arrRecords["hd_lv1_score"] <= $score) {
mysql_query("UPDATE wp_hdquizscore SET `hd_lv1_score`='" . $score . "' WHERE ID ='" . $_SESSION['user_id'] . "'", $dbLocalhost);
}
}
if ($arrRecords == "") {
mysql_query("INSERT INTO wp_hdquizscore ( ID, display_name, hd_lv1_score) VALUES
('" . $_SESSION['user_id'] . "','" . $_SESSION['user'] . "','" . $score . "')");
} else {
header ('Location: /wordpress/level-1-handling-depression/');
}
header ('Location: /wordpress/level-1-handling-depression/');
?>