ok
Direktori : /home2/selectio/www/tnpsctestbatch.com/api/ |
Current File : /home2/selectio/www/tnpsctestbatch.com/api/test-subject.php |
<?php ob_start(); session_start(); include "../config/config.php"; if($_POST['type']=="get_subject_question_res"){ $answer = $_POST['answer']; $user_id = ""; $id = $_POST['id']; $test_type = $_POST['test_type']; $date = date('Y-m-d'); if(isset($_COOKIE['users_id'])){ $cookies_user_id = $_COOKIE['users_id']; error_log($cookies_user_id); $final_result_sql = $pdo->prepare("SELECT * FROM `tbl_subject_result` WHERE user_id = $cookies_user_id AND type = $test_type AND question_id = $id AND date='$date' "); $final_result_sql->execute(); $final = $final_result_sql->fetchAll(PDO::FETCH_ASSOC); $final_data = $final_result_sql->rowCount(); } else { $user_rand_id = date( 'ds' ).rand(10,10000); error_log("else set cookies Date " .$user_rand_id); setcookie("users_id", $user_rand_id, time() + 2 * 24 * 60 * 60, '/', 'tnpsctestbatch.com' ); $final_data = ""; } $statement = $pdo->prepare("SELECT * FROM `tbl_questions` WHERE id='".$id."'"); $statement->execute(); $result = $statement->fetchAll(PDO::FETCH_ASSOC); $totalrow = $statement->rowCount(); if($final_data>0){ if(isset($_SESSION['user_exam'])){ $user_sessionid = $_SESSION['user_exam']['id']; $ids = $final[0]['id']; $statements = $pdo->prepare("UPDATE `tbl_subject_result` SET `user_id`=?,`question_id`=?,`select_option`=? WHERE id=?"); $results=$statements->execute(array($user_sessionid,$id,$answer,$ids)); } else{ $ids = $final[0]['id']; $statements = $pdo->prepare("UPDATE `tbl_subject_result` SET `user_id`=?,`question_id`=?,`select_option`=? WHERE id=?"); $results=$statements->execute(array($cookies_user_id,$id,$answer,$ids)); } }else{ if(isset($_SESSION['user_exam'])){ $user_id = $_SESSION['user_exam']['id']; $statements = $pdo->prepare("INSERT INTO `tbl_subject_result`(`user_id`, `question_id`,`select_option`,`date`,`type`,`status`) VALUES (?,?,?,?,?,?)"); $results=$statements->execute(array($user_id,$id,$answer,$date,$test_type,1)); }else{ if(isset($_COOKIE['users_id'])){ error_log("if user cookies id" .$cookies_user_id); $statements = $pdo->prepare("INSERT INTO `tbl_subject_result`(`user_id`, `question_id`,`select_option`,`date`,`type`,`status`) VALUES (?,?,?,?,?,?)"); $results=$statements->execute(array($cookies_user_id,$id,$answer,$date,$test_type,1)); }else{ error_log("last if condition is working"); $statements = $pdo->prepare("INSERT INTO `tbl_subject_result`(`user_id`, `question_id`,`select_option`,`date`,`type`,`status`) VALUES (?,?,?,?,?,?)"); $results=$statements->execute(array($user_rand_id,$id,$answer,$date,$test_type,1)); } } $final=array(); $data['question_id']=$id; $data['answer']=$answer; $data['type']=$test_type; $final[]=$data; $m=json_encode($final); setcookie("Name", $m, time() + 2 * 24 * 60 * 60, '/', 'tnpsctestbatch.com' ); } if($result){ if(isset($_COOKIE['users_id'])){ error_log("SELECT * FROM `tbl_subject_result` WHERE user_id = $cookies_user_id AND type = $test_type AND date='$date'" ); $statement_mock = $pdo->prepare("SELECT * FROM `tbl_subject_result` WHERE user_id = $cookies_user_id AND type = $test_type AND date='$date'" ); $statement_mock->execute(); $result_mock = $statement_mock->fetchAll(PDO::FETCH_ASSOC); $total_mock = $statement_mock->rowCount(); } $response['total_mock']=$total_mock; $response['correct_ans']=$result[0]['correct_answer']; $response['error']=1; }else{ $response['error']=0; $response['correct_ans']=$result[0]['correct_answer']; } echo json_encode($response); } ?>