query('SELECT "current_right_answer" FROM "Games" WHERE "ID" = $1', array($uid)) ['data'][0]['current_right_answer']; $correct = $correct_answer == $chosen_answer ? true : false; $score = $correct_answer == $chosen_answer ? calculate_points($time) : 0; if($uid == '') { $error = 13101; } else if($time == 0) { $error = 13102; } else if($chosen_answer == -1) { $error = 13103; } else if($db->query('SELECT EXISTS (SELECT 1 FROM "Games" WHERE "ID" = $1)', array($uid)) ['data'][0]['exists'] == 'f') { $error = 13104; } else { $old_points = $db->query('SELECT "current_score" FROM "Games" WHERE "ID" = $1', array($uid)) ['data'][0]['current_score']; $new_points = $old_points + $score; $db->query('UPDATE "Games" SET "current_score" = $1 WHERE "ID" = $2', array($new_points, $uid)); $results = array('correct' => $correct, 'correctPos' => $correct_answer, 'score' => $score); $old_time = $db->query('SELECT "total_time" FROM "Games" WHERE "ID" = $1', array($uid)) ['data'][0]['total_time']; $new_time = $old_time + $time; $db->query('UPDATE "Games" SET "total_time" = $1 WHERE "ID" = $2', array($new_time, $uid)); if($db->query('SELECT EXISTS (SELECT 1 FROM "GamesQuestions" WHERE "Games_ID" = $1)',array($uid)) ['data'][0]['exists'] == 't') { $next_question = Question::get_next_question($db, $uid); $data = array('results' => $results, 'next' => $next_question); } else { $end = array('score' => $new_points, 'time' => $new_time); $data = array('results' => $results, 'end' => $end); $db->query('DELETE FROM "Games" WHERE "ID" = $1', array($uid)); } } $response = Database::create_response($data, $error); print_r($response); ?>