-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendoftest.php
More file actions
157 lines (135 loc) · 6.16 KB
/
Copy pathendoftest.php
File metadata and controls
157 lines (135 loc) · 6.16 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
if (isset($_POST['submit1']) || isset($_POST['submit2'])) {
$config = parse_ini_file('../../stradtest_config.ini');
$connection = mysqli_connect('localhost', $config['username'], $config['password'], $config['dbname']);
if (mysqli_connect_errno()) {
die("Connection failed: " . mysqli_connect_error());
}
// Numeric fields
$age = isset($_POST['age']) ? (int) $_POST['age'] : 0;
$yearsOfTraining = isset($_POST['yearsOfTraining']) ? (int) $_POST['yearsOfTraining'] : 0;
$weeklyHoursOfTraining = isset($_POST['weeklyHoursOfTraining']) ? (int) $_POST['weeklyHoursOfTraining'] : 0;
$secondsTaken = isset($_POST['secondsTaken']) ? (int) $_POST['secondsTaken'] : 0;
$professionalMusician = isset($_POST['professionalMusician']) ? (int) $_POST['professionalMusician'] : 0;
$musicologistTheorist = isset($_POST['musicologistTheorist']) ? 1 : 0;
$musicTeacher = isset($_POST['musicTeacher']) ? 1 : 0;
$instrumentTeacher = isset($_POST['instrumentTeacher']) ? 1 : 0;
$producer = isset($_POST['producer']) ? 1 : 0;
$none = isset($_POST['none']) ? 1 : 0;
// String fields
$instrumentTraining = isset($_POST['instrumentTraining']) ? $_POST['instrumentTraining'] : '';
$instrumentsPlayed = isset($_POST['instrumentsPlayed']) ? $_POST['instrumentsPlayed'] : '';
$comments = isset($_POST['comments']) ? $_POST['comments'] : '';
$results1 = isset($_POST['results1']) ? $_POST['results1'] : '';
$freeComments = isset($_POST['freeComments']) ? $_POST['freeComments'] : '';
$tf1text = isset($_POST['tf1textname']) ? $_POST['tf1textname'] : '';
$tf2text = isset($_POST['tf2textname']) ? $_POST['tf2textname'] : '';
$tf3text = isset($_POST['tf3textname']) ? $_POST['tf3textname'] : '';
$tf4text = isset($_POST['tf4textname']) ? $_POST['tf4textname'] : '';
$tf5text = isset($_POST['tf5textname']) ? $_POST['tf5textname'] : '';
$tf6text = isset($_POST['tf6textname']) ? $_POST['tf6textname'] : '';
$tf7text = isset($_POST['tf7textname']) ? $_POST['tf7textname'] : '';
$tf8text = isset($_POST['tf8textname']) ? $_POST['tf8textname'] : '';
$tf9text = isset($_POST['tf9textname']) ? $_POST['tf9textname'] : '';
$tf10text = isset($_POST['tf10textname']) ? $_POST['tf10textname'] : '';
$tf11text = isset($_POST['tf11textname']) ? $_POST['tf11textname'] : '';
$tf12text = isset($_POST['tf12textname']) ? $_POST['tf12textname'] : '';
$tf13text = isset($_POST['tf13textname']) ? $_POST['tf13textname'] : '';
$tf14text = isset($_POST['tf14textname']) ? $_POST['tf14textname'] : '';
// --- Insert 1: main answers table ---
$stmt = mysqli_prepare($connection,
"INSERT INTO answers_stradtest (
answer_age,
answer_instrumentTraining,
answer_instrumentsPlayed,
answer_yearsOfTraining,
answer_weeklyHoursOfTraining,
answer_professionalMusician,
answer_musicologistTheorist,
answer_musicTeacher,
answer_instrumentTeacher,
answer_producer,
answer_none,
answer_comments,
answer_results1,
D00comments, D01comments, D02comments, D03comments,
D04comments, D05comments, D06comments, D07comments,
D08comments, D09comments, D10comments, D11comments,
D12comments, D13comments,
answer_secondsTaken
) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
);
if (!$stmt) {
die("Prepare failed: " . mysqli_error($connection));
}
// 28 params: i,s,s,i,i,i,i,i,i,i,i,s,s,s*14,i
mysqli_stmt_bind_param(
$stmt,
'issiiiiiiiissssssssssssssssi',
$age,
$instrumentTraining,
$instrumentsPlayed,
$yearsOfTraining,
$weeklyHoursOfTraining,
$professionalMusician,
$musicologistTheorist,
$musicTeacher,
$instrumentTeacher,
$producer,
$none,
$comments,
$results1,
$tf1text, $tf2text, $tf3text, $tf4text,
$tf5text, $tf6text, $tf7text, $tf8text,
$tf9text, $tf10text, $tf11text, $tf12text,
$tf13text, $tf14text,
$secondsTaken
);
if (!mysqli_stmt_execute($stmt)) {
echo 'Error in insert: ', mysqli_stmt_error($stmt);
}
mysqli_stmt_close($stmt);
// --- Insert 2: free comments table ---
$stmt2 = mysqli_prepare($connection,
"INSERT INTO survey_answers_stradtest (answer_freeComments) VALUES (?)"
);
if (!$stmt2) {
die("Prepare failed: " . mysqli_error($connection));
}
mysqli_stmt_bind_param($stmt2, 's', $freeComments);
if (!mysqli_stmt_execute($stmt2)) {
echo 'Error in insert: ', mysqli_stmt_error($stmt2);
}
mysqli_stmt_close($stmt2);
mysqli_close($connection);
// --- Show results ---
$pieces = explode(",", $results1);
readfile("thankyou_header.html");
echo "Your violin evaluation results from worst to best:";
echo "<br><br>";
$violinNames = [
"D00" => "Stradivari 1679 Hellier",
"D01" => "Stradivari 1690 Auer",
"D02" => "Stradivari 1692 Oliveira",
"D03" => "Stradivari 1701 Dushkin",
"D04" => "Stradivari 1707 La Cathedrale",
"D05" => "Stradivari 1708 Ruby",
"D06" => "Stradivari 1710 Vieuxtemps, Hauser",
"D07" => "Stradivari 1709 King Maximilian",
"D08" => "Stradivari 1715 Baron Knoop",
"D09" => "Stradivari 1722 Jupiter",
"D10" => "Stradivari 1723 Kiesewetter",
"D11" => "Stradivari 1727 Dupont",
"D12" => "Stradivari 1734 Willemotte",
"D13" => "Stradivari 1736 Muntz",
];
foreach ($pieces as $value) {
$value = trim($value);
if (isset($violinNames[$value])) {
echo htmlspecialchars($violinNames[$value]) . "<br>";
}
}
echo "<br>";
readfile('thankyou_footer.html');
}
?>