Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #This is going to be the user login check and will set a cookie
- use DBI;
- use CGI qw(:standard);
- use strict;
- #Connection error
- sub showErrorMsgAndExit {
- print header(), start_html(-title=>shift);
- print (shift);
- print end_html();
- exit;
- }
- #Connecting to the database
- my $dbUsername = "root";
- my $dbPassword = "password";
- my $dsn = "DBI:mysql:f18final:localhost";
- my $dbh = DBI->connect($dsn, $dbUsername, $dbPassword, {PrintError => 0});
- #error checking
- if(!$dbh) {
- print header(), start_html(-title=>"Error connecting to DB");
- print ("Unable to connec to the database");
- print end_html();
- exit;
- }
- print header;
- print start_html(-title=>'Edit Classes');
- #Need to execute sql command and then iterate row by row
- my $sql = "SELECT * FROM tblclasses";
- my $sth = $dbh->prepare($sql);
- $sth->execute();
- my $passedCredits = 0;
- my $attemptedCredits = 0;
- my $totalHonor = 0;
- my $gpa = 0.000;
- ##SSSssssssearch part
- print "<table border=solid 1px>"; #start of table
- print "<tr><th>Class Name</th><th>Department</th><th>Class Number</th><th>Grade</th><th>Credits</th>";
- print "</tr>";
- while( my @row = $sth->fetchrow_array) {
- print "<tr><td>";
- print $row[1];
- print "</td>";
- print "<td>";
- print $row[2];
- print "</td>";
- print "<td>";
- print $row[3];
- print "</td>";
- print "<td>";
- print $row[4];
- print "</td>";
- print "<td>";
- print $row[5];
- print "</td>";
- $attemptedCredits = $attemptedCredits + $row[5];
- if($row[4] == 'A' || $row[4] == 'a') {
- $passedCredits = $passedCredits + $row[5];
- $gpa = $gpa + (4 * $row[5]);
- }
- elsif($row[4] == 'B' || $row[4] == 'b') {
- $passedCredits = $passedCredits + $row[5];
- $gpa = $gpa + (3 * $row[5]);
- }
- elsif($row[4] == 'C' || $row[4] == 'c') {
- $passedCredits = $passedCredits + $row[5];
- $gpa = $gpa + (2 * $row[5]);
- }
- elsif($row[4] == 'D' || $row[4] == 'd') {
- $passedCredits = $passedCredits + $row[5];
- $gpa = $gpa + (1 * $row[5]);
- }
- elsif($row[4] == 'F' || $row[4] == 'f') {
- }
- elsif($row[4] == 'S' || $row[4] == 's') {
- $passedCredits = $passedCredits + $row[5];
- }
- elsif($row[4] == 'U' || $row[4] == 'u') {
- }
- #calculate
- print "</tr>";
- }
- print "</table>";
- #Need to make a table and populate it with text boxes of all the class data
- print "</table>"; #End of table
- $gpa = $gpa / $attemptedCredits;
- ##RReturn values
- print qq{
- <table border = '1px solid'>
- <tr>
- <td>
- Attempted Credits
- </td>
- <td>
- Passed Credits
- </td>
- <td>
- GPA
- </td>
- </tr>
- <tr>
- <td>
- $attemptedCredits
- </td>
- <td>
- $passedCredits
- </td>
- <td>
- $gpa
- </td>
- </tr>
- </table>
- };
- print "<form action=http://localhost/cgi-bin/actions.pl method = 'post' >";
- print "<input type = 'submit' name = 'submit' value = 'More Options'>";
- print "</form>";
- print "<form action=http://localhost/cgi-bin/searchingTran.pl method = 'post' >";
- print "<input type = 'text' name = 'search' size = '25'><br>";
- print "<input type = 'submit' name = 'submit' value = 'Search'>";
- print "</form>";
- print end_html();
- #!/usr/bin/perl
- #This is going to be the user login check and will set a cookie
- use DBI;
- use CGI qw(:standard);
- use strict;
- #Connection error
- sub showErrorMsgAndExit {
- print header(), start_html(-title=>shift);
- print (shift);
- print end_html();
- exit;
- }
- #Connecting to the database
- my $dbUsername = "root";
- my $dbPassword = "password";
- my $dsn = "DBI:mysql:f18final:localhost";
- my $dbh = DBI->connect($dsn, $dbUsername, $dbPassword, {PrintError => 0});
- #error checking
- if(!$dbh) {
- print header(), start_html(-title=>"Error connecting to DB");
- print ("Unable to connec to the database");
- print end_html();
- exit;
- }
- print header;
- print start_html(-title=>'Edit Classes');
- #Need to execute sql command and then iterate row by row
- my $sql = "SELECT * FROM tblclasses";
- my $sth = $dbh->prepare($sql);
- $sth->execute();
- my $passedCredits = 0;
- my $attemptedCredits = 0;
- my $totalHonor = 0;
- my $gpa = 0.000;
- ##SSSssssssearch part
- print "<table border=solid 1px>"; #start of table
- print "<tr><th>Class Name</th><th>Department</th><th>Class Number</th><th>Grade</th><th>Credits</th>";
- print "</tr>";
- while( my @row = $sth->fetchrow_array) {
- print "<tr><td>";
- print $row[1];
- print "</td>";
- print "<td>";
- print $row[2];
- print "</td>";
- print "<td>";
- print $row[3];
- print "</td>";
- print "<td>";
- print $row[4];
- print "</td>";
- print "<td>";
- print $row[5];
- print "</td>";
- $attemptedCredits = $attemptedCredits + $row[5];
- if($row[4] == 'A' || $row[4] == 'a') {
- $passedCredits = $passedCredits + $row[5];
- $gpa = $gpa + (4 * $row[5]);
- }
- elsif($row[4] == 'B' || $row[4] == 'b') {
- $passedCredits = $passedCredits + $row[5];
- $gpa = $gpa + (3 * $row[5]);
- }
- elsif($row[4] == 'C' || $row[4] == 'c') {
- $passedCredits = $passedCredits + $row[5];
- $gpa = $gpa + (2 * $row[5]);
- }
- elsif($row[4] == 'D' || $row[4] == 'd') {
- $passedCredits = $passedCredits + $row[5];
- $gpa = $gpa + (1 * $row[5]);
- }
- elsif($row[4] == 'F' || $row[4] == 'f') {
- }
- elsif($row[4] == 'S' || $row[4] == 's') {
- $passedCredits = $passedCredits + $row[5];
- }
- elsif($row[4] == 'U' || $row[4] == 'u') {
- }
- #calculate
- print "</tr>";
- }
- print "</table>";
- #Need to make a table and populate it with text boxes of all the class data
- print "</table>"; #End of table
- $gpa = $gpa / $attemptedCredits;
- ##RReturn values
- print qq{
- <table border = '1px solid'>
- <tr>
- <td>
- Attempted Credits
- </td>
- <td>
- Passed Credits
- </td>
- <td>
- GPA
- </td>
- </tr>
- <tr>
- <td>
- $attemptedCredits
- </td>
- <td>
- $passedCredits
- </td>
- <td>
- $gpa
- </td>
- </tr>
- </table>
- };
- print "<form action=http://localhost/cgi-bin/actions.pl method = 'post' >";
- print "<input type = 'submit' name = 'submit' value = 'More Options'>";
- print "</form>";
- print "<form action=http://localhost/cgi-bin/searchingTran.pl method = 'post' >";
- print "<input type = 'text' name = 'search' size = '25'><br>";
- print "<input type = 'submit' name = 'submit' value = 'Search'>";
- print "</form>";
- print end_html();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement