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

$id = $_POST['id'];
$title = $_POST['title'];
$description = $_POST['description'];
$due_date = $_POST['due_date'];

$file_sql = "";

if (!empty($_FILES['file']['name'])) {
    $file = "uploads/" . time().$_FILES['file']['name'];
    move_uploaded_file($_FILES['file']['tmp_name'], $file);
    $file_sql = ", file_path='$file'";
}

$conn->query("
UPDATE homework 
SET title='$title', description='$description', due_date='$due_date' $file_sql
WHERE homework_id=$id
");

header("Location: add_homework.php");