-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaveRecord.php
64 lines (52 loc) · 1.55 KB
/
saveRecord.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
<?php
require_once 'assets/config/config.php';
require_once "vendor/autoload.php";
use Miniature\Database as DB;
use Miniature\Users as Login;
$login = new Login();
$username = (isset($_SESSION['id'])) ? $login->username($_SESSION['id']) : null;
if (!$username) {
header("Location: game.php");
exit();
}
$conn = DB::getInstance();
$pdo = $conn->getConnection();
$data = json_decode(file_get_contents('php://input'), true);
function updateQuiz($data, $pdo) {
$query = "UPDATE trivia_questions "
. "SET "
. "user_id = :user_id, "
. "question = :question, "
. "answer1 = :answer1, "
. "answer2 = :answer2, "
. "answer3 = :answer3, "
. "answer4 = :answer4, "
. "correct = :correct, "
. 'hidden = :hidden '
. "WHERE id = :id";
$stmt = $pdo->prepare($query);
$stmt->execute([
':user_id' => $data['user_id'],
':question' => $data['question'],
':answer1' => $data['answer1'],
':answer2' => $data['answer2'],
':answer3' => $data['answer3'],
':answer4' => $data['answer4'],
':correct' => $data['correct'],
':hidden' => $data['hidden'],
':id' => $data['id']
]);
return \TRUE;
}
$result = updateQuiz($data, $pdo);
if ($result) {
output('Data Successfully Updated');
}
function errorOutput($output, $code = 500) {
http_response_code($code);
echo json_encode($output);
}
function output($output) {
http_response_code(200);
echo json_encode($output);
}