Presentation is loading. Please wait.

Presentation is loading. Please wait.

DBM Databases Please use speaker notes for additional information!

Similar presentations


Presentation on theme: "DBM Databases Please use speaker notes for additional information!"— Presentation transcript:

1 DBM Databases Please use speaker notes for additional information!

2 Click here.

3

4

5 Make any changes you want. Click here.

6

7

8 Click here to retrieve the information.

9 Click here.

10

11

12 Click here

13 Click here.

14 BCC Students BCC Student eMail List The CIS Department is publishing a newsletter to keep students up-to-date with changes that are being made. This page will give you the opportunity to sign up for the newsletter or remove your name from the newsletter list. Student Name: Student Major: Student Option: eMail address:

15 #!/usr/bin/perl #bccstudents1.cgi - add and remove names from CIS mailing list print "Content-type: text/html\n\n"; use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); use SDBM_File; use Fcntl; use strict; #declare variables my ($button, $name, $major, $option, $email); #assign values to variables $button = param('button'); $name = param('stuname'); $major = param('major'); $option = param('option'); $email = param('email'); if ($button eq "Add me to the CIS Mailing List") { add(); } elsif ($button eq "Remove me from the CIS Mailing List") { remove(); } elsif ($button eq "View my information") { view() } exit; #*****user-defined functions***** The functions add(), remove() and view() are shown on the next few pages.

16 sub view { #declare variable my %mail; #open database, view record, close database tie(%mail, "SDBM_File", "cislist", O_RDONLY, 0666) or die "Error opening cislist. $!, stopped"; ($name, $major, $option) = split(/,/, $mail{$email}); if (exists($mail{$email})) { untie(%mail); #create Web page print " \n"; print " CIS Newsletter Mailing List \n"; print " \n"; print "Student Name: \n"; print "Student Major: \n"; print "Student Option: \n"; print "eMail address: \n"; print " \n"; print " OR...Click here to return to main page \n"; print " \n"; } else { untie(%mail); #create Web page print " \n"; print " CIS Newsletter Mailing List \n"; print "Record does not exist. \n"; print " Click here to return to main page \n"; print " \n"; } } #endview This is the code that opens the database. Note that I am opening in as readonly. I then take the record that the key located and split it into the appropriate fields so I can display them on the screen.

17 sub add { #declare variable my %mail; #open database, add record, close database tie(%mail, "SDBM_File", "cislist", O_CREAT|O_RDWR, 0666) or die "Error opening cislist. $!, stopped"; $mail{$email} = "$name,$major,$option"; untie(%mail); #create Web page print " \n"; print " CIS Newsletter Mailing List \n"; print "You are on our list to receive your newsletter at $email. \n"; print " Click here to return to main page \n"; print " \n"; } #end add

18 sub remove { #declare variables my (%mail, $msg); #open database tie(%mail, "SDBM_File", "cislist", O_RDWR, 0) or die "Error opening cislist. $!, stopped"; #determine if user's information is in the database if (exists($mail{$email})) { delete($mail{$email}); $msg = "Mail will not be sent to $email"; } else { $msg = "Our mailing list does not include $email."; } #close database untie(%mail); #create Web page print " \n"; print " CIS Newsletter Mailing List \n"; print "$msg \n"; print " Click here to return to main page \n"; print " \n"; } #end remove

19 #!/usr/bin/perl #bccstudents1a.cgi - change names from CIS mailing list print "Content-type: text/html\n\n"; use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); use SDBM_File; use Fcntl; use strict; #declare variables my ($button, $name, $major, $option, $email); #assign values to variables $button = param('button'); $name = param('stuname'); $major = param('major'); $option = param('option'); $email = param('email'); if ($button eq "Update Mailing List") { change(); } exit; #*****user-defined functions*****

20 sub change { #declare variable my %mail; #open database, add record, close database tie(%mail, "SDBM_File", "cislist", O_CREAT|O_RDWR, 0666) or die "Error opening cislist. $!, stopped"; $mail{$email} = "$name,$major,$option"; untie(%mail); #create Web page print " \n"; print " CIS Newsletter Mailing List \n"; print "The information has been changed. \n"; print "Name: $name \n"; print "Major: $major \n"; print "Option: $option \n"; print "eMail: $email \n"; print " Click here to return to main page \n"; print " \n"; } #end change


Download ppt "DBM Databases Please use speaker notes for additional information!"

Similar presentations


Ads by Google