<?php
require_once "../includes/db.php"; $db=db();

$id=(int)$_POST['id'];
$name=$_POST['name']; 
$nic=$_POST['nic'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$course_id=(int)$_POST['course_id'];
$unit_id=(int)$_POST['unit_id'];

// Get course + unit names
$c=$db->prepare("SELECT course_name FROM courses WHERE id=?"); $c->bind_param("i",$course_id); $c->execute(); $course=$c->get_result()->fetch_assoc()['name'];
$u=$db->prepare("SELECT name FROM units WHERE id=?"); $u->bind_param("i",$unit_id); $u->execute(); $unit=$u->get_result()->fetch_assoc()['name'];

$stmt=$db->prepare("UPDATE students SET name=?, nic_number=?, email=?, phone=?, course_name=?, unit_exam=? WHERE id=?");
$stmt->bind_param("ssssssi",$name,$nic,$email,$phone,$course,$unit,$id);
$stmt->execute();

echo "OK";
