diff --git a/Script.php b/Script.php index f664eee..eecb7cd 100644 --- a/Script.php +++ b/Script.php @@ -913,18 +913,32 @@ if (!empty($_GET["ignoreremarking"])) { #Assign TA if (!empty($_GET["assignTA"])) { - $id = mysqli_real_escape_string($con, $_GET["id"]); $ta = mysqli_real_escape_string($con, $_GET["ta"]); - $sql = "INSERT INTO `course_ta`(`Course_ID`, `TA`) VALUES ('$id','$ta')"; + // Check if the TA is already assigned to the course + $check_sql = "SELECT * FROM `course_ta` WHERE `Course_ID`='$id' AND `TA`='$ta'"; + $check_result = $con->query($check_sql); - if ($con->query($sql) === TRUE) { - - $_SESSION["info_Admin_Courses"] = $type . " Course TA Assigned "; - header("Location: Admin.php"); + if ($check_result->num_rows > 0) { + // Alert user about the duplicate assignment + echo ""; } else { - echo "Error: " . $sql . "
" . $con->error; + // Proceed with the TA assignment + $sql = "INSERT INTO `course_ta`(`Course_ID`, `TA`) VALUES ('$id','$ta')"; + + if ($con->query($sql) === TRUE) { + $_SESSION["info_Admin_Courses"] = $type . " Course TA Assigned "; + header("Location: Admin.php"); + } else { + echo ""; + } } }