
<?php
include('server.php');
if(!$_SESSION['loggedin']) {
    header("location: index.php");
}

session_start();
error_reporting(0);

//intializing variable
$name = "";
$email = "";
$roll = "";
$coursetaken = "";
$company = "";
$roundprovided = "";
$roundcleared = "";
$story = "";

$error = array();
$servername = "localhost";
$username = "root";
$pass = "";
$dbname = "webpage";
// Create connection
$db = mysqli_connect($servername, $username, $pass, $dbname);



if(isset($_POST['submit'])){
	$name = mysqli_real_escape_string($db, $_POST['name']);
	$roll = mysqli_real_escape_string($db, $_POST['roll']);
	$email = mysqli_real_escape_string($db, $_POST['email']);
	$coursetaken = mysqli_real_escape_string($db, $_POST['coursetaken']);
	$company = mysqli_real_escape_string($db, $_POST['companyname']);
	$story = mysqli_real_escape_string($db, $_POST['story']);
	$student_id = mysqli_real_escape_string($db, $_POST['student_id']);
	$roundprovided = implode(",", $_POST['roundprovided']);
	$roundcleared = implode(",", $_POST['roundcleared']);


	$created = date('Y-m-d H:i:s');

	$story = str_replace(array("\n","\n","\\n","\\n"),"<br/>",$story);
	// echo "$story";
	// die;

	if(empty($name)){array_push($error, "Name is required");}
	if(empty($roll)) {array_push($error, "roll is required");}
	if(empty($email)){array_push($error, "Email is required");}
	if(empty($coursetaken)){array_push($error, "Course Name is required");}
	if(empty($company)){array_push($error, "Company Name is required");}
	if(empty($story)){array_push($error, "Story is required");}

	

	if(count($error)==0)
	{
		$inset_query ="INSERT INTO posts(student_id,name,roll,email,coursetaken,companyname,story,roundprovided,roundcleared,created_at) VALUES ('$student_id','$name','$roll','$email','$coursetaken','$company','$story','$roundprovided','$roundcleared','$created')";

		mysqli_query($db, $inset_query) or die(mysqli_error());

		header("location: profile.php");


	}

}



















?>