<?php
include_once "../../includes/connectConfig.php";

if($_POST)
{	
    $pstrec = (isset($_POST["pstrec"])) ? test_input($_POST["pstrec"]) : '';
	$post_title = test_input($_POST["posttitle"]);
	$anounc_ebrief =  test_input($_POST['anouncebrief']);
	
	if($_POST['post_info'] == "post-faq")
	{
		//INSERT INTO TABLE
		$prd = $db_con->prepare("INSERT INTO faqspost(fq_title, fq_info) VALUES(:post_title, :briefpost)");
		
		$prd->bindParam(':post_title',$post_title);
		$prd->bindParam(':briefpost',$anounc_ebrief);
		$prd->execute();
		
		$output["runstt"] = "grant";
		$output["errorreason"] = "Question Posted";
		echo json_encode($output);
		exit;
	}
	elseif($_POST['post_info'] == "edit-faq")
	{
		$prd = $db_con->prepare("UPDATE faqspost SET fq_title=:post_title, fq_info=:briefpost WHERE fq_id=:pstrec");
		
		$prd->bindParam(':post_title',$post_title);
		$prd->bindParam(':briefpost',$anounc_ebrief);
		$prd->bindParam(':pstrec',$pstrec);
		$prd->execute();
		
		
		$output["runstt"] = "grant";
		$output["errorreason"] = "Post Updated";
		echo json_encode($output);
		exit;
	}
	else
	{
		$output["runstt"] = "warant";
		$output["errorreason"] = "";
		echo json_encode($output);
		exit;
	}

}
?>