Guest User

Untitled

a guest
Jan 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. <?php
  2. function badinput($msg)
  3. {
  4. echo <<< BADINPUT
  5. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  6. <html>
  7. <head><?php
  8. function badinput($msg)
  9. {
  10. echo <<< BADINPUT
  11. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  12. <html>
  13. <head>
  14. <title>Bad Input</title>
  15. </head>
  16. <body>
  17. <h1>Error</h1>
  18. <p>Input could not be used because $msg.</p>
  19. </body>
  20. </html>
  21. BADINPUT;
  22. }
  23. function connectToDatabase()
  24. {
  25. global $mysqli;
  26. $mysqli = new mysqli('localhost', 'root', '12341234', '110ass3');
  27.  
  28. if(mysqli_connect_errno()){
  29. $problem = mysqli_connect_errno();
  30. badinput($problem);
  31. exit;
  32. }
  33. }
  34. function display_form()
  35. {
  36. $subjectname=array();
  37. $n=0;
  38. $m=0;
  39. connectToDatabase();
  40. echo"<html><head><script src='formcheck.js'></script>
  41.  
  42. <script type='text/javascript'>
  43. var jq=jQuery.noConflict();
  44. jq(document).ready(function(){
  45. jq('#thtitle1').click(function(){
  46. jq('#mytable').tablesorter({sortList:[[0,0]]});
  47. });
  48. jq('#thtitle2').click(function(){
  49. jq('#mytable').tablesorter({sortList:[[1,0]]});
  50. });
  51. jq('#thtitle3').click(function(){
  52. jq('#mytable').tablesorter({sortList:[[2,0]]});
  53. });
  54. jq('#thtitle4').click(function(){
  55. jq('#mytable').tablesorter({sortList:[[3,0]]});
  56. });
  57. });
  58. </script>
  59. </head><body><center><h1>Faculty subject offerings</h1>
  60. </center><h1>Faculty</h1><form><select id='users' name='users' onchange='showuser(this.value)'>";
  61. $mysqli=new mysqli('localhost','root','12341234','Exercise5');
  62. $stmt=$mysqli->query("select * from ErehwonSubjects");
  63. while($row=$stmt->fetch_array())
  64. {
  65.  
  66. $subjectname[$n]=$row['Subject'];
  67. $n++;
  68. }
  69. echo "<option>Select Subject </option>";
  70.  
  71. for($k=0;$k<$n;$k++)
  72. {
  73. if($k+1>=$n)
  74. {
  75. break;
  76. }
  77. if($subjectname[$k]!=$subjectname[$k+1])
  78. {
  79. echo"<option value='$subjectname[$k]'>";
  80. echo $subjectname[$k];
  81. echo "</option>";
  82. $m++;
  83. }
  84.  
  85.  
  86. }
  87. $w=$n-1;
  88. echo"<option value='$subjectname[$w]'>";
  89. echo $subjectname[($n-1)];
  90. echo"</option></select></form><form><div id='txtHint'></div></form>";
  91. echo "</body></html>";
  92. }
  93.  
  94. display_form();
  95. ?>
  96.  
  97.  
  98. <title>Bad Input</title>
  99. </head>
  100. <body>
  101. <h1>Error</h1>
  102. <p>Input could not be used because $msg.</p>
  103. </body>
  104. </html>
  105. BADINPUT;
  106. }
  107. function connectToDatabase()
  108. {
  109. global $mysqli;
  110. $mysqli = new mysqli('localhost', 'root', '12341234', '110ass3');
  111.  
  112. if(mysqli_connect_errno()){
  113. $problem = mysqli_connect_errno();
  114. badinput($problem);
  115. exit;
  116. }
  117. }
  118. function display_form()
  119. {
  120. $subjectname=array();
  121. $n=0;
  122. $m=0;
  123. connectToDatabase();
  124. echo"<html><head><script src='formcheck.js'></script>
  125.  
  126. <script type='text/javascript'>
  127. var jq=jQuery.noConflict();
  128. jq(document).ready(function(){
  129. jq('#thtitle1').click(function(){
  130. jq('#mytable').tablesorter({sortList:[[0,0]]});
  131. });
  132. jq('#thtitle2').click(function(){
  133. jq('#mytable').tablesorter({sortList:[[1,0]]});
  134. });
  135. jq('#thtitle3').click(function(){
  136. jq('#mytable').tablesorter({sortList:[[2,0]]});
  137. });
  138. jq('#thtitle4').click(function(){
  139. jq('#mytable').tablesorter({sortList:[[3,0]]});
  140. });
  141. });
  142. </script>
  143. </head><body><center><h1>Faculty subject offerings</h1>
  144. </center><h1>Faculty</h1><form><select id='users' name='users' onchange='showuser(this.value)'>";
  145. $mysqli=new mysqli('localhost','root','12341234','Exercise5');
  146. $stmt=$mysqli->query("select * from ErehwonSubjects");
  147. while($row=$stmt->fetch_array())
  148. {
  149.  
  150. $subjectname[$n]=$row['Subject'];
  151. $n++;
  152. }
  153. echo "<option>Select Subject </option>";
  154.  
  155. for($k=0;$k<$n;$k++)
  156. {
  157. if($k+1>=$n)
  158. {
  159. break;
  160. }
  161. if($subjectname[$k]!=$subjectname[$k+1])
  162. {
  163. echo"<option value='$subjectname[$k]'>";
  164. echo $subjectname[$k];
  165. echo "</option>";
  166. $m++;
  167. }
  168.  
  169.  
  170. }
  171. $w=$n-1;
  172. echo"<option value='$subjectname[$w]'>";
  173. echo $subjectname[($n-1)];
  174. echo"</option></select></form><form><div id='txtHint'></div></form>";
  175. echo "</body></html>";
  176. }
  177.  
  178. display_form();
  179. ?>
Add Comment
Please, Sign In to add comment