<?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);
    
    $title = trim($request->title);
    $username = trim($request->username);  //string
    $statement = trim($request->statement); //string
    $tc1 = trim($request->tc1_inp);
    $out1 = trim($request->tc1_out);
    $tc2 = trim($request->tc2_inp);
    $out2 = trim($request->tc2_out);
    $stime = trim($request->start_time); //string
    $etime = trim($request->end_time)

    $sql = "INSERT INTO questions(title,username,statement,tc1,out1,tc2,out2,stime,etime) VALUES ('$title','$username','$statement','$tc1','$out1','$tc2','$out2','$stime','$etime')";

    if($result = $mysqli->query($sql)){
        $msg = "question uploaded";
        echo json_encode($msg);
    }
    else{
        $msg = "question already exists";
        echo json_encode($msg);
    }

}

?>