20
DBM Databases Please use speaker notes for additional information!

DBM Databases

  • Upload
    ami

  • View
    88

  • Download
    0

Embed Size (px)

DESCRIPTION

DBM Databases. Please use speaker notes for additional information!. Click here. Click here. Click here. Make any changes you want. Click here. Click here. Click here. Click here to retrieve the information. Click here. Click here. Click here. Click here. Click here. - PowerPoint PPT Presentation

Citation preview

Page 1: DBM Databases

DBM Databases

Please use speaker notes for additional information!

Page 2: DBM Databases

Click here.

Page 3: DBM Databases

Click here.

Page 4: DBM Databases

Click here.

Page 5: DBM Databases

Make any changes you want.

Click here.

Page 6: DBM Databases

Click here.

Page 7: DBM Databases

Click here.

Page 8: DBM Databases

Click here to retrieve the information.

Page 9: DBM Databases

Click here.

Page 10: DBM Databases

Click here.

Page 11: DBM Databases

Click here.

Page 12: DBM Databases

Click here

Page 13: DBM Databases

Click here.

Page 14: DBM Databases

<!bccstudents1.html><html><head><title>BCC Students</title></head><BODY><h1>BCC Student eMail List</h1><form action="http://www.pgrocer.com/cgi-bin/db/bccstudents1.cgi" method=post>The CIS Department is publishing a newsletter to keep students up-to-date with changes thatare being made. This page will give you the opportunity to sign up for the newsletter or remove your name from the newsletter list.<br><br>Student Name: <input type=text name=stuname size=25><br>Student Major:<input type=text name=major size=3><br>Student Option:<input type=text name=option size=3><br>eMail address: <input type=text name=email size=50><br><br><input type=submit name=button value="Add me to the CIS Mailing List"><input type=submit name=button value="Remove me from the CIS Mailing List"><br><br><input type=submit name=button value="View my information"><input type=reset value="Reset"></form></body></html>

Page 15: DBM Databases

#!/usr/bin/perl#bccstudents1.cgi - add and remove names from CIS mailing listprint "Content-type: text/html\n\n";use CGI::Carp qw(fatalsToBrowser);use CGI qw(:standard);use SDBM_File;use Fcntl;use strict;#declare variablesmy ($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.

Page 16: DBM Databases

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 "<html>\n"; print "<head><title>CIS Newsletter Mailing List</title><basefont size=5></head>\n"; print "<h1>CIS Newsletter Mailing List</h1>\n"; print "<form action='http://www.pgrocer.com/cgi-bin/db/bccstudents1a.cgi' method=post>\n"; print "Student Name: <input type=text name=stuname value='$name' size=25><br>\n"; print "Student Major: <input type=text name=major value='$major' size=3><br>\n"; print "Student Option: <input type=text name=option value='$option' size=3><br>\n"; print "eMail address: <input type=text name=email value=$email size=50><br><br>\n"; print "<input type=submit name=button value='Update Mailing List'><br><br>\n"; print "<a href='http://www.pgrocer.com/db/bccstudents1.html'>OR...Click here to return to main page</a>\n"; print "</body></html>\n"; } else { untie(%mail); #create Web page print "<html>\n"; print "<head><title>CIS Newsletter Mailing List</title><basefont size=5></head>\n"; print "<h1>CIS Newsletter Mailing List</h1>\n"; print "Record does not exist.<br><br>\n"; print "<a href='http://www.pgrocer.com/db/bccstudents1.html'>Click here to return to main page</a>\n"; print "</body></html>\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.

Page 17: DBM Databases

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 "<html>\n"; print "<head><title>CIS Newsletter Mailing List</title><basefont size=5></head>\n"; print "<h1>CIS Newsletter Mailing List</h1>\n"; print "You are on our list to receive your newsletter at $email.<br><br>\n"; print "<a href='http://www.pgrocer.com/db/bccstudents1.html'>Click here to return to main page</a>\n"; print "</body></html>\n";

} #end add

Page 18: DBM Databases

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 "<html>\n"; print "<head><title>CIS Newsletter Mailing List</title><basefont size=5></head>\n"; print "<h1>CIS Newsletter Mailing List</h1>\n"; print "$msg<br><br>\n"; print "<a href='http://www.pgrocer.com/db/bccstudents1.html'>Click here to return to main page</a>\n"; print "</body></html>\n";} #end remove

Page 19: DBM Databases

#!/usr/bin/perl#bccstudents1a.cgi - change names from CIS mailing listprint "Content-type: text/html\n\n";use CGI::Carp qw(fatalsToBrowser);use CGI qw(:standard);use SDBM_File;use Fcntl;use strict;#declare variablesmy ($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*****

Page 20: DBM Databases

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 "<html>\n"; print "<head><title>CIS Newsletter Mailing List</title><basefont size=5></head>\n"; print "<h1>CIS Newsletter Mailing List</h1>\n"; print "The information has been changed.<br>\n"; print "Name: $name<br>\n"; print "Major: $major<br>\n"; print "Option: $option<br>\n"; print "eMail: $email<br><br><br>\n"; print "<a href='http://www.pgrocer.com/db/bccstudents1.html'>Click here to return to main page</a>\n"; print "</body></html>\n";} #end change