Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.56 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 classID, classname, department, classnum, grade, credits FROM tblclasses";
  37. my $sth = $dbh->prepare($sql);
  38. $sth->execute();
  39. print "<table border=solid 1px>"; #start of table
  40. print "<tr><th>Class Name</th><th>Department</th><th>Class Number</th><th>Grade</th><th>Credits</th><td>Edit class</td>";
  41. print "</tr>";
  42. while( my @row = $sth->fetchrow_array) {
  43. print "<tr><td>";
  44. print $row[1];
  45. print "</td>";
  46. print "<td>";
  47. print $row[2];
  48. print "</td>";
  49. print "<td>";
  50. print $row[3];
  51. print "</td>";
  52. print "<td>";
  53. print $row[4];
  54. print "</td>";
  55. print "<td>";
  56. print $row[5];
  57. print "</td>";
  58. print "<td>";
  59. print "<form action=http://localhost/cgi-bin/editing.pl method = 'post' >";
  60. my $classid = $row[0];
  61. my $classname = $row[1];
  62. my $dep = $row[2];
  63. my $classnum = $row[3];
  64. my $grade = $row[4];
  65. my $credit = $row[5];
  66. print "<input type='hidden' name='classid' value='$classid' />" ;
  67. print "<input type='hidden' name='classname' value='$classname' />" ;
  68. print "<input type='hidden' name='dep' value='$dep' />" ;
  69. print "<input type='hidden' name='classnum' value='$classnum' />" ;
  70. print "<input type='hidden' name='grade' value='$grade' />" ;
  71. print "<input type='hidden' name='credit' value='$credit' />" ;
  72. prin#!/usr/bin/perl
  73. #This is going to be the user login check and will set a cookie
  74.  
  75. use DBI;
  76. use CGI qw(:standard);
  77.  
  78. use strict;
  79.  
  80. #Connection error
  81. sub showErrorMsgAndExit {
  82. print header(), start_html(-title=>shift);
  83. print (shift);
  84. print end_html();
  85. exit;
  86. }
  87.  
  88. #Connecting to the database
  89. my $dbUsername = "root";
  90. my $dbPassword = "password";
  91.  
  92. my $dsn = "DBI:mysql:f18final:localhost";
  93. my $dbh = DBI->connect($dsn, $dbUsername, $dbPassword, {PrintError => 0});
  94.  
  95. #error checking
  96. if(!$dbh) {
  97. print header(), start_html(-title=>"Error connecting to DB");
  98. print ("Unable to connec to the database");
  99. print end_html();
  100. exit;
  101. }
  102.  
  103. print header;
  104. print start_html(-title=>'Edit Classes');
  105.  
  106. #Need to execute sql command and then iterate row by row
  107. my $sql = "SELECT classID, classname, department, classnum, grade, credits FROM tblclasses";
  108. my $sth = $dbh->prepare($sql);
  109. $sth->execute();
  110. print "<table border=solid 1px>"; #start of table
  111. print "<tr><th>Class Name</th><th>Department</th><th>Class Number</th><th>Grade</th><th>Credits</th><td>Edit class</td>";
  112. print "</tr>";
  113. while( my @row = $sth->fetchrow_array) {
  114. print "<tr><td>";
  115. print $row[1];
  116. print "</td>";
  117. print "<td>";
  118. print $row[2];
  119. print "</td>";
  120. print "<td>";
  121. print $row[3];
  122. print "</td>";
  123. print "<td>";
  124. print $row[4];
  125. print "</td>";
  126. print "<td>";
  127. print $row[5];
  128. print "</td>";
  129. print "<td>";
  130. print "<form action=http://localhost/cgi-bin/editing.pl method = 'post' >";
  131. my $classid = $row[0];
  132. my $classname = $row[1];
  133. my $dep = $row[2];
  134. my $classnum = $row[3];
  135. my $grade = $row[4];
  136. my $credit = $row[5];
  137. print "<input type='hidden' name='classid' value='$classid' />" ;
  138. print "<input type='hidden' name='classname' value='$classname' />" ;
  139. print "<input type='hidden' name='dep' value='$dep' />" ;
  140. print "<input type='hidden' name='classnum' value='$classnum' />" ;
  141. print "<input type='hidden' name='grade' value='$grade' />" ;
  142. print "<input type='hidden' name='credit' value='$credit' />" ;
  143. print "<input type = 'submit' name = 'submit' value = 'Edit'>";
  144. print "</form>";
  145. print "</td>";
  146. print "</tr>";
  147.  
  148. }
  149.  
  150.  
  151. print "</table>";
  152.  
  153. #Need to make a table and populate it with text boxes of all the class data
  154.  
  155.  
  156. print "</table>"; #End of table
  157.  
  158.  
  159. print end_html();
  160. t "<input type = 'submit' name = 'submit' value = 'Edit'>";
  161. print "</form>";
  162. print "</td>";
  163. print "</tr>";
  164.  
  165. }
  166.  
  167.  
  168. print "</table>";
  169.  
  170. #Need to make a table and populate it with text boxes of all the class data
  171.  
  172.  
  173. print "</table>"; #End of table
  174.  
  175.  
  176. print end_html();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement