ok

Mini Shell

Direktori : /home2/selectio/public_html/tnpsctestbatch.com/api/
Upload File :
Current File : /home2/selectio/public_html/tnpsctestbatch.com/api/get-subject-result.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 = 1;
    $date = date('Y-m-d');
    $subject_id = $_POST['subject_id'];
    $topics_id = $_POST['topics_id'];
    $standared_id = $_POST['standared_id'];

         if(isset($_COOKIE['users_id'])){
            $cookies_user_id = $_COOKIE['users_id'];
            
            
            $final_result_sql = $pdo->prepare("SELECT * FROM `tbl_subject_result` WHERE user_id = $cookies_user_id 
            AND subject_id = $subject_id AND topics_id = $topics_id AND standared_id = $standared_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);
		        
		        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`,`subject_id`,`topics_id`,`standared_id`,`status`) VALUES (?,?,?,?,?,?,?,?,?)");
            $results=$statements->execute(array($user_id,$id,$answer,$date,$test_type,$subject_id,$topics_id,$standared_id,1)); 
		}else{
		   
		    if(isset($_COOKIE['users_id'])){
	
		     
                $statements = $pdo->prepare("INSERT INTO `tbl_subject_result`(`user_id`, `question_id`,`select_option`,`date`,`type`,`subject_id`,`topics_id`,`standared_id`,`status`) VALUES (?,?,?,?,?,?,?,?,?)");
                $results=$statements->execute(array($cookies_user_id,$id,$answer,$date,$test_type,$subject_id,$topics_id,$standared_id,1)); 
		    }else{
                
		        $statements = $pdo->prepare("INSERT INTO `tbl_subject_result`(`user_id`, `question_id`,`select_option`,`date`,`type`,`subject_id`,`topics_id`,`standared_id`,`status`) VALUES (?,?,?,?,?,?,?,?,?)");
                $results=$statements->execute(array($user_rand_id,$id,$answer,$date,$test_type,$subject_id,$topics_id,$standared_id,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){
		    $total_mock ='';
		    if(isset($_COOKIE['users_id'])){

		      $statement_mock = $pdo->prepare("SELECT * FROM `tbl_subject_result` WHERE user_id = $cookies_user_id AND subject_id = $subject_id AND topics_id = $topics_id AND standared_id = $standared_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);
 
}


?>

Zerion Mini Shell 1.0