-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_question.php
executable file
·48 lines (48 loc) · 1.14 KB
/
get_question.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
<?php
include "config.php";
if (isset($_SESSION['nick'])) {
$nick = $_POST['nick'];
try{
$con = new PDO('mysql:dbname='.SQL_DB.';host='.SQL_HOST,SQL_USER,SQL_PASS);
$stmt = $con->prepare("SELECT * FROM game where nick = ?");
$stmt->execute(array($nick));
$row = $stmt->fetch();
if(!$row){
echo "Invalid Nick<br>";
die();
}else{
$json = array();
if($row['level']<=END_LEVEL){
$stmt = $con->prepare("SELECT * FROM questions where level = ?");
$stmt->execute(array($row['level']));
$question = $stmt->fetch();
if($question){
$ques = array(
"level"=> $question[0],
"qtitle"=>$question[1],
"image"=>$question[2],
"hint"=>$question[4],
"hint_type"=>$question[5],
"score"=>$row['score'],
"skip"=>(SKIP - $row['skip'])
);
array_push($json,$ques);
echo json_encode($json);
}else{
echo "Database Error";
}
}else{
$ques = array("level"=>"FINISH");
array_push($json,$ques);
echo json_encode($json);
}
$con = null;
}
}catch(PDOException $ex){
echo "Error!: " . $ex->getMessage() . "<br/>";
die();
}
}else{
echo "Please Login";
}
?>