Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #This is going to be the user login check and will set a cookie
  3.  
  4. use DBI;
  5. use CGI qw(:standard);
  6.  
  7. use strict;
  8.  
  9. #Connection error
  10. sub showErrorMsgAndExit {
  11. print header(), start_html(-title=>shift);
  12. print (shift);
  13. print end_html();
  14. exit;
  15. }
  16.  
  17. #Connecting to the database
  18. my $dbUsername = "root";
  19. my $dbPassword = "password";
  20.  
  21. my $dsn = "DBI:mysql:f18final:localhost";
  22. my $dbh = DBI->connect($dsn, $dbUsername, $dbPassword, {PrintError => 0});
  23.  
  24. #error checking
  25. if(!$dbh) {
  26. print header(), start_html(-title=>"Error connecting to DB");
  27. print ("Unable to connec to the database");
  28. print end_html();
  29. exit;
  30. }
  31.  
  32. print header;
  33. print start_html(-title=>'Edit Classes');
  34.  
  35. #Need to execute sql command and then iterate row by row
  36. my $sql = "SELECT * FROM tblclasses";
  37. my $sth = $dbh->prepare($sql);
  38. $sth->execute();
  39.  
  40. my $passedCredits = 0;
  41. my $attemptedCredits = 0;
  42. my $totalHonor = 0;
  43. my $gpa = 0.000;
  44.  
  45.  
  46. ##SSSssssssearch part
  47.  
  48.  
  49. print "<table border=solid 1px>"; #start of table
  50. print "<tr><th>Class Name</th><th>Department</th><th>Class Number</th><th>Grade</th><th>Credits</th>";
  51. print "</tr>";
  52. while( my @row = $sth->fetchrow_array) {
  53. print "<tr><td>";
  54. print $row[1];
  55. print "</td>";
  56. print "<td>";
  57. print $row[2];
  58. print "</td>";
  59. print "<td>";
  60. print $row[3];
  61. print "</td>";
  62. print "<td>";
  63. print $row[4];
  64. print "</td>";
  65. print "<td>";
  66. print $row[5];
  67. print "</td>";
  68.  
  69. $attemptedCredits = $attemptedCredits + $row[5];
  70. if($row[4] == 'A' || $row[4] == 'a') {
  71. $passedCredits = $passedCredits + $row[5];
  72. $gpa = $gpa + (4 * $row[5]);
  73. }
  74. elsif($row[4] == 'B' || $row[4] == 'b') {
  75. $passedCredits = $passedCredits + $row[5];
  76. $gpa = $gpa + (3 * $row[5]);
  77. }
  78. elsif($row[4] == 'C' || $row[4] == 'c') {
  79. $passedCredits = $passedCredits + $row[5];
  80. $gpa = $gpa + (2 * $row[5]);
  81. }
  82. elsif($row[4] == 'D' || $row[4] == 'd') {
  83. $passedCredits = $passedCredits + $row[5];
  84. $gpa = $gpa + (1 * $row[5]);
  85. }
  86. elsif($row[4] == 'F' || $row[4] == 'f') {
  87.  
  88. }
  89. elsif($row[4] == 'S' || $row[4] == 's') {
  90. $passedCredits = $passedCredits + $row[5];
  91. }
  92. elsif($row[4] == 'U' || $row[4] == 'u') {
  93.  
  94. }
  95.  
  96. #calculate
  97.  
  98. print "</tr>";
  99.  
  100. }
  101.  
  102.  
  103. print "</table>";
  104.  
  105. #Need to make a table and populate it with text boxes of all the class data
  106.  
  107.  
  108. print "</table>"; #End of table
  109.  
  110. $gpa = $gpa / $attemptedCredits;
  111.  
  112. ##RReturn values
  113. print qq{
  114. <table border = '1px solid'>
  115. <tr>
  116. <td>
  117. Attempted Credits
  118. </td>
  119. <td>
  120. Passed Credits
  121. </td>
  122. <td>
  123. GPA
  124. </td>
  125. </tr>
  126. <tr>
  127. <td>
  128. $attemptedCredits
  129. </td>
  130. <td>
  131. $passedCredits
  132. </td>
  133. <td>
  134. $gpa
  135. </td>
  136. </tr>
  137. </table>
  138. };
  139. print "<form action=http://localhost/cgi-bin/actions.pl method = 'post' >";
  140. print "<input type = 'submit' name = 'submit' value = 'More Options'>";
  141. print "</form>";
  142. print "<form action=http://localhost/cgi-bin/searchingTran.pl method = 'post' >";
  143. print "<input type = 'text' name = 'search' size = '25'><br>";
  144. print "<input type = 'submit' name = 'submit' value = 'Search'>";
  145. print "</form>";
  146. print end_html();
  147. #!/usr/bin/perl
  148. #This is going to be the user login check and will set a cookie
  149.  
  150. use DBI;
  151. use CGI qw(:standard);
  152.  
  153. use strict;
  154.  
  155. #Connection error
  156. sub showErrorMsgAndExit {
  157. print header(), start_html(-title=>shift);
  158. print (shift);
  159. print end_html();
  160. exit;
  161. }
  162.  
  163. #Connecting to the database
  164. my $dbUsername = "root";
  165. my $dbPassword = "password";
  166.  
  167. my $dsn = "DBI:mysql:f18final:localhost";
  168. my $dbh = DBI->connect($dsn, $dbUsername, $dbPassword, {PrintError => 0});
  169.  
  170. #error checking
  171. if(!$dbh) {
  172. print header(), start_html(-title=>"Error connecting to DB");
  173. print ("Unable to connec to the database");
  174. print end_html();
  175. exit;
  176. }
  177.  
  178. print header;
  179. print start_html(-title=>'Edit Classes');
  180.  
  181. #Need to execute sql command and then iterate row by row
  182. my $sql = "SELECT * FROM tblclasses";
  183. my $sth = $dbh->prepare($sql);
  184. $sth->execute();
  185.  
  186. my $passedCredits = 0;
  187. my $attemptedCredits = 0;
  188. my $totalHonor = 0;
  189. my $gpa = 0.000;
  190.  
  191.  
  192. ##SSSssssssearch part
  193.  
  194.  
  195. print "<table border=solid 1px>"; #start of table
  196. print "<tr><th>Class Name</th><th>Department</th><th>Class Number</th><th>Grade</th><th>Credits</th>";
  197. print "</tr>";
  198. while( my @row = $sth->fetchrow_array) {
  199. print "<tr><td>";
  200. print $row[1];
  201. print "</td>";
  202. print "<td>";
  203. print $row[2];
  204. print "</td>";
  205. print "<td>";
  206. print $row[3];
  207. print "</td>";
  208. print "<td>";
  209. print $row[4];
  210. print "</td>";
  211. print "<td>";
  212. print $row[5];
  213. print "</td>";
  214.  
  215. $attemptedCredits = $attemptedCredits + $row[5];
  216. if($row[4] == 'A' || $row[4] == 'a') {
  217. $passedCredits = $passedCredits + $row[5];
  218. $gpa = $gpa + (4 * $row[5]);
  219. }
  220. elsif($row[4] == 'B' || $row[4] == 'b') {
  221. $passedCredits = $passedCredits + $row[5];
  222. $gpa = $gpa + (3 * $row[5]);
  223. }
  224. elsif($row[4] == 'C' || $row[4] == 'c') {
  225. $passedCredits = $passedCredits + $row[5];
  226. $gpa = $gpa + (2 * $row[5]);
  227. }
  228. elsif($row[4] == 'D' || $row[4] == 'd') {
  229. $passedCredits = $passedCredits + $row[5];
  230. $gpa = $gpa + (1 * $row[5]);
  231. }
  232. elsif($row[4] == 'F' || $row[4] == 'f') {
  233.  
  234. }
  235. elsif($row[4] == 'S' || $row[4] == 's') {
  236. $passedCredits = $passedCredits + $row[5];
  237. }
  238. elsif($row[4] == 'U' || $row[4] == 'u') {
  239.  
  240. }
  241.  
  242. #calculate
  243.  
  244. print "</tr>";
  245.  
  246. }
  247.  
  248.  
  249. print "</table>";
  250.  
  251. #Need to make a table and populate it with text boxes of all the class data
  252.  
  253.  
  254. print "</table>"; #End of table
  255.  
  256. $gpa = $gpa / $attemptedCredits;
  257.  
  258. ##RReturn values
  259. print qq{
  260. <table border = '1px solid'>
  261. <tr>
  262. <td>
  263. Attempted Credits
  264. </td>
  265. <td>
  266. Passed Credits
  267. </td>
  268. <td>
  269. GPA
  270. </td>
  271. </tr>
  272. <tr>
  273. <td>
  274. $attemptedCredits
  275. </td>
  276. <td>
  277. $passedCredits
  278. </td>
  279. <td>
  280. $gpa
  281. </td>
  282. </tr>
  283. </table>
  284. };
  285. print "<form action=http://localhost/cgi-bin/actions.pl method = 'post' >";
  286. print "<input type = 'submit' name = 'submit' value = 'More Options'>";
  287. print "</form>";
  288. print "<form action=http://localhost/cgi-bin/searchingTran.pl method = 'post' >";
  289. print "<input type = 'text' name = 'search' size = '25'><br>";
  290. print "<input type = 'submit' name = 'submit' value = 'Search'>";
  291. print "</form>";
  292. print end_html();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement