Commit a006484b authored by Paarth's avatar Paarth

rating handling

parent 0c6caa33
......@@ -11,15 +11,21 @@ $postData = file_get_contents("php://input");
if(isset($postData) && !empty($postData)){
$request = json_decode($postData);
$username = mysqli_real_escape_string($mysqli, trim($request->username));
$title = mysqli_real_escape_string($mysqli, trim($request->title));
$out = mysqli_real_escape_string($mysqli, trim($request->out));
$ind = mysqli_real_escape_string($mysqli, trim($request->ind));
$isSubmit = trim($request->isSubmit);
if((int)$ind==0){
$sql = "SELECT out1 FROM questions WHERE title='$title'";
if($result = mysqli_query($mysqli,$sql)->fetch_all(MYSQLI_ASSOC)){
$bool = 0;
if($result[0]['out1'] === $out){
$bool=1;
if($isSubmit){
$sql1 = "UPDATE users SET rating = rating + 5 WHERE username='$username'";
mysqli_query($mysqli,$sql1);
}
}
echo json_encode($bool);
}
......@@ -30,11 +36,13 @@ if(isset($postData) && !empty($postData)){
else{
$sql = "SELECT out2 FROM questions WHERE title='$title'";
if($result = mysqli_query($mysqli,$sql)->fetch_all(MYSQLI_ASSOC)){
// echo json_encode($result);
// exit(0);
$bool = 0;
if($result[0]['out2'] === $out){
$bool=1;
if($isSubmit){
$sql1 = "UPDATE users SET rating = rating + 5 WHERE username='$username'";
mysqli_query($mysqli,$sql1);
}
}
echo json_encode($bool);
......
<?php
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
header("Content-Type: application/json; charset=UTF-8");
include_once("database.php");
$postData = file_get_contents("php://input");
if (isset($postData) && !empty($postData)) {
$request = json_decode($postData,true);
$username = mysqli_real_escape_string($mysqli, trim($request->username));
$bool = trim($request->)
$sql0 = "UPDATE users set n_attempts = n_attempts+1 where username = '$username'";
mysqli_query($mysqli,$sql0);
if($bool){
$sql1 = "UPDATE users set correct_timeline=CONCAT(correct_timeline,'1') where username = '$username'";
}
else{
$sql1 = "UPDATE users set correct_timeline=CONCAT(correct_timeline,'0') where username = '$username'";
}
mysqli_query($mysqli,$sql1);
}
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment