<?php

session_start();

include("../config/db.php");

if($_SERVER['REQUEST_METHOD'] != 'POST'){

    exit;

}

$user_id = $_SESSION['user_id'];

$contract_id =
intval($_POST['contract_id']);

$note =
trim($_POST['note']);

if(empty($note)){

    exit;

}

$note_safe =
$conn->real_escape_string($note);

$conn->query("
INSERT INTO contract_notes (
    contract_id,
    user_id,
    note_text
) VALUES (
    '$contract_id',
    '$user_id',
    '$note_safe'
)
");

header("Location: /pages/contract_view.php?id=$contract_id");
exit;