Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 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=>'Add Classes');
  34.  
  35. #Get the information the user entered
  36. my $id = param('classid');
  37. my $className = param('classname');
  38. my $department = param('department');
  39. my $classnum = param('classnum');
  40. my $grade = param('grade');
  41. my $credits = param('credit');
  42. print "$id $className, $department, $classnum, $grade, $credits";
  43. #first sql check to see if username is already taken
  44. my $check = "UPDATE tblclasses(classname, department, classnum, grade, credits) VALUES (?, ?, ?, ?, ?) WHERE classID = $id";
  45. my $sth = $dbh->prepare($check);
  46. $sth->execute($className, $department, $classnum, $grade,$credits);
  47. print "<h1>Success</h1>";
  48. print "<form action=http://localhost/cgi-bin/edit.pl method = 'post'>";
  49. print "<input type = 'submit' name = 'submit' value = 'Update Another'>";
  50. print "</form>";
  51. print "<form action=http://localhost/cgi-bin/actions.pl method = 'post'>";
  52. print "<input type = 'submit' name = 'submit' value = 'Back to actions'>";
  53. print "</form>";
  54.  
  55.  
  56. print end_html();
  57. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement