. **/ //config $sql_user="squiz"; $sql_passwd="squizuserforgood"; $sql_db="squiz"; $quiz_tag=0; $db=new PDO("mysql:host=localhost;dbname=".$sql_db.";charset=utf8", $sql_user, $sql_passwd); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if(isset($_GET['list'])){ if($quiz_tag!=0){ $sql=$db->prepare("SELECT id, name, description FROM tests WHERE allowed=1 and tag=:tag"); $sql->execute(array(":tag"=>$quiz_tag)); } else{ $sql=$db->prepare("SELECT id, name, description FROM tests WHERE allowed=1"); $sql->execute(); } $obj=array(); while($row=$sql->fetch(PDO::FETCH_ASSOC)){ array_push($obj, array("name"=>$row['name'], "description"=>$row['description'], "file"=>"//".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?getQuiz=".$row['id'])); } header("Content-type: text/json; charset=UTF-8"); echo json_encode($obj); die(); } if(isset($_GET['getQuiz'])){ $sql=$db->prepare("SELECT quiz FROM tests WHERE id=:id"); $sql->execute(array(":id"=>$_GET['getQuiz'])); $res=$sql->fetch(PDO::FETCH_ASSOC); header("Content-type: text/json; charset=UTF-8"); echo $res['quiz']; die(); } if(isset($_POST['submitResult']) && isset($_POST['submitResult_submitter'])){ $sql=$db->prepare("INSERT INTO results (submitter, answered) VALUES (:submitter, :answered)"); $sql->execute(array(":submitter"=>$_POST['submitResult_submitter'], ":answered"=>$_POST['submitResult'])); $id=$db->lastInsertId(); echo $id; die(); } if(isset($_GET['getResult'])){ $sql=$db->prepare("SELECT COUNT(id) AS count, submitter, time, answered FROM results WHERE id=:id"); $sql->execute(array(":id"=>$_GET['getResult'])); $res=$sql->fetch(PDO::FETCH_ASSOC); if($res['count']<1){ echo "not found"; } else{ $obj=array("submitter"=>$res['submitter'], "time"=>$res['time'], "answered"=>$res['answered']); header("Content-type: text/json; charset=UTF-8"); echo json_encode($obj); die(); } } if(isset($_POST['submitQuiz']) && isset($_POST['submitQuiz_tag']) && isset($_POST['submitQuiz_name']) && isset($_POST['submitQuiz_description'])){ $sql=$db->prepare("INSERT INTO tests (name, description, quiz, tag) VALUES (:name, :desc, :quiz, :tag)"); $sql->execute(array(":name"=>$_POST['submitQuiz_name'], ":desc"=>$_POST['submitQuiz_description'], ":quiz"=>$_POST['submitQuiz'], ":tag"=>$_POST['submitQuiz_tag'])); $id=$db->lastInsertId(); $link="https://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']."?getQuiz=".$id; echo $link; die(); }