From 7b680430601b53f057fe0ee80e78d34affe3dd12 Mon Sep 17 00:00:00 2001 From: yaaqob <3237084594@qq.com> Date: Mon, 27 Nov 2023 10:40:35 +0800 Subject: [PATCH] Fixed Bug418 --- Script.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Script.php b/Script.php index c0bfd7e..537b668 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 ""; + } } }