<?php
session_start();
include "db.php";

if(!isset($_SESSION['user_id'])) exit('Not logged in');

if(isset($_POST['course_id'], $_POST['progress'])){
    $user_id = $_SESSION['user_id'];
    $course_id = $_POST['course_id'];
    $progress = $_POST['progress'];

    $stmt = $conn->prepare("UPDATE user_courses SET progress = ? WHERE user_id = ? AND course_id = ?");
    $stmt->bind_param("iii", $progress, $user_id, $course_id);
    if($stmt->execute()){
        echo "success";
    } else {
        echo "error";
    }
}
?>
