Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 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. print "<input type = 'submit' name = 'submit' value = 'Edit'>";
  73. print "</form>";
  74. print "</td>";
  75. print "</tr>";
  76.  
  77. }
  78.  
  79.  
  80. print "</table>";
  81.  
  82. #Need to make a table and populate it with text boxes of all the class data
  83.  
  84.  
  85. print "</table>"; #End of table
  86.  
  87.  
  88. print end_html();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement