<?php
session_start();
include 'connect.php';

if(!isset($_SESSION['email'])){
    header("Location: login");
    exit();
}
$user_id = $_SESSION['user_id']; 

if(isset($_POST['submit'])){
    $username = trim($_POST['name']);
    $email = trim($_POST['email']);
    $feedback = trim($_POST['message']);


    $stmt = $conn->prepare(
        "INSERT INTO feedback (user_id,name,email,feedback) 
         VALUES (?, ?, ?, ?)"
    );
    $stmt->bind_param(
        "isss",
        $user_id,
        $username,
        $email,
        $feedback

    );
    $stmt -> execute();
    echo "<script>alert('feedback posted successfully!'); window.location.href = 'index';</script>";
    exit;
}

?>