<?php
include('server.php');
if(!$_SESSION['loggedin']) {
    header("location: index.php");
}
$a = $_GET['posts_id'];
echo "<pre/>";
    print_r($_GET);
    
if(isset($_POST['update'])) {
    // update code below
    // $a = $_SESSION['posts_id'];
    // echo "<pre/>";
    // print_r($a);
    // die;
    $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 = mysqli_real_escape_string($db, $_POST['roundprovided']);
    // $roundprovided = $_POST['roundprovided'];
    $roundprovided = implode(",", $_POST['roundprovided']);
    $roundcleared = implode(",", $_POST['roundcleared']);
    $story = str_replace(array("\n","\n","\\n","\\n"),"<br/>",$story);

    // echo $story;
    // die;
    $created = date('Y-m-d H:i:s');
    
    $sql = "UPDATE posts SET name = '$name',roll = '$roll' , email = '$email', coursetaken = '$coursetaken',companyname='$company',story='$story',roundprovided='$roundprovided',roundcleared='$roundcleared',created_at='$created' WHERE id=$a";
    // die;
    $result = mysqli_query($db, $sql);
    header("location: profile.php");
}

?>