subjectStudentAdd.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. }
  16. else{
  17. $sql_query="INSERT INTO students_subjects (`degreeID`, `subjectID`, `studentID`) VALUES ('$degreeID', '$subjectID', '$studentID')";
  18. $result=mysqli_query($db,$sql_query);
  19. if($result){
  20. header("Location: /admin/admin.php?msg=Student added to subject");
  21. }
  22. else{
  23. $error="sql error";
  24. echo $sql_query;
  25. }
  26. }
  27. }
  28. else{
  29. $degreeID=mysqli_real_escape_string($db,$_GET['degreeID']);
  30. $studentID=mysqli_real_escape_string($db,$_GET['studentID']);
  31. $subjectID=mysqli_real_escape_string($db,$_GET['subjectID']);
  32. }
  33. ?>
  34. <html>
  35. <head>
  36. <title>Add a student to subject</title>
  37. <link rel="stylesheet" type="text/css" href="adminStyle.css">
  38. </head>
  39. <body>
  40. <?php
  41. include($root . "/admin/header.php");
  42. ?>
  43. <li><a href="/admin/subjectsStudentsList.php?subjectID=<?php echo $subjectID?>&&degreeID=<?php echo $degreeID?>">Back</a></li>
  44. <form action="/admin/subjectStudentAdd.php" method="post" id="subjectForm">
  45. <label for="degreeID">Degree ID:</label><br>
  46. <input type="text" id="degreeID" name="degreeID" value="<?php echo $degreeID ?>"><br>
  47. <label for="subjectID">Subject ID:</label><br>
  48. <input type="text" id="subjectID" name="subjectID" value="<?php echo $subjectID ?>"><br>
  49. <label for="studentID">Student:</label><br>
  50. <select name="studentID" id="studentID" name="studentID" form="subjectForm">
  51. <?php
  52. $tSQL="select * from users join user_info on users.username=user_info.login where usertype='student'";
  53. $tResult=mysqli_query($db,$tSQL);
  54. while($student=mysqli_fetch_assoc($tResult)){
  55. echo '<option value="' . $student['username'] . '">' . $student['full_name'] . '</option>';
  56. }
  57. ?>
  58. </select>
  59. <input type="submit" value="Submit">
  60. </form>
  61. <div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php if(isset($error)){echo $error;} ?></div>
  62. <?php
  63. include($root . "/admin/footer.php");
  64. ?>
  65. </body>
  66. </html>