subjectStudentAdd.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. $root = $_SERVER['DOCUMENT_ROOT'];
  3. include($root . "/util/session.php"); //checks that the user is logged in
  4. include($root . "/util/privilege_check.php");
  5. checkPrivilege("admin");
  6. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  7. $degreeID = mysqli_real_escape_string($db, $_POST['degreeID']);
  8. $subjectID = mysqli_real_escape_string($db, $_POST['subjectID']);
  9. $studentID = mysqli_real_escape_string($db, $_POST['studentID']);
  10. $sql_query = "select * from students_subjects where degreeID = '$degreeID' and subjectID='$subjectID' and studentID='$studentID'";
  11. $result = mysqli_query($db, $sql_query);
  12. //check if user exists
  13. if (mysqli_num_rows($result) != 0) {
  14. $error = "Relation exists";
  15. } else {
  16. $sql_query = "INSERT INTO students_subjects (`degreeID`, `subjectID`, `studentID`) VALUES ('$degreeID', '$subjectID', '$studentID')";
  17. $result = mysqli_query($db, $sql_query);
  18. if ($result) {
  19. header("Location: /admin/admin.php?msg=Student added to subject");
  20. } else {
  21. $error = "sql error";
  22. echo $sql_query;
  23. }
  24. }
  25. } else {
  26. $degreeID = mysqli_real_escape_string($db, $_GET['degreeID']);
  27. $studentID = mysqli_real_escape_string($db, $_GET['studentID']);
  28. $subjectID = mysqli_real_escape_string($db, $_GET['subjectID']);
  29. }
  30. ?>
  31. <head>
  32. <title>Add a student to subject</title>
  33. <link rel="stylesheet" type="text/css" href="adminStyle.css">
  34. </head>
  35. <?php
  36. include($root . "/admin/header.php");
  37. ?>
  38. <main>
  39. <html>
  40. <body>
  41. <li><a href="/admin/subjectsStudentsList.php?subjectID=<?php echo $subjectID ?>&&degreeID=<?php echo $degreeID ?>">Back</a></li>
  42. <form action="/admin/subjectStudentAdd.php" method="post" id="subjectForm">
  43. <label for="degreeID">Degree ID:</label><br>
  44. <input type="text" id="degreeID" name="degreeID" value="<?php echo $degreeID ?>"><br>
  45. <label for="subjectID">Subject ID:</label><br>
  46. <input type="text" id="subjectID" name="subjectID" value="<?php echo $subjectID ?>"><br>
  47. <label for="studentID">Student:</label><br>
  48. <select name="studentID" id="studentID" name="studentID" form="subjectForm">
  49. <?php
  50. $tSQL = "select * from users join user_info on users.username=user_info.login where usertype='student'";
  51. $tResult = mysqli_query($db, $tSQL);
  52. while ($student = mysqli_fetch_assoc($tResult)) {
  53. echo '<option value="' . $student['username'] . '">' . $student['full_name'] . '</option>';
  54. }
  55. ?>
  56. </select>
  57. <input type="submit" value="Submit">
  58. </form>
  59. <div style="font-size:11px; color:#cc0000; margin-top:10px"><?php if (isset($error)) {
  60. echo $error;
  61. } ?></div>
  62. </body>
  63. </html>
  64. </main>
  65. <?php
  66. include($root . "/admin/footer.php");
  67. ?>