<?php

    include($_SERVER['DOCUMENT_ROOT'] . "/_ps2020/config/connect.php");

    session_start();

    $user_id = 0;
    $name = $_REQUEST['name'];
    $email = $_REQUEST['email'];
    $type = $_REQUEST['type'];
    $subject = $_REQUEST['subject'];
    $message = $_REQUEST['message'];

    // session_start();
    if(isset($_SESSION['userID'])){
        // $name = $_SESSION['user'];
        // $email = $_SESSION['email'];

        $result = $conn->query("SELECT * FROM user_account WHERE user_id = ".$_SESSION['userID']."");
        if($result){
            while($row = $result->fetch_assoc()){
                $user_id = $row['user_id'];
            }
        }
    }


   // generate 'id'
        $result = $conn->query("select * from feedback ORDER BY feedback_id DESC LIMIT 1;");
            if($result){
                $id = 1;
                while($row = $result->fetch_assoc()){
                    $id = $row['feedback_id'] + 1;
                }
            }

    // $subject = 'hi';
    // echo 'ID: '.$id.', userID: '.$user_id.', name: '.$name.', email: '.$email.', subject: '.$subject.', type: '.$type.', message: '.$message;

    if ($conn->query("INSERT INTO feedback VALUES ('$id', '$user_id', '$name', '$email', '$subject', '$type', '$message')") === TRUE) {
        echo 1;
    }else{
		echo 0;
	}

    $conn->close();

?>