1 / 20

DBM Databases

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.

ami
Télécharger la présentation

DBM Databases

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DBM Databases Please use speaker notes for additional information!

  2. Click here.

  3. Click here.

  4. Click here.

  5. Make any changes you want. Click here.

  6. Click here.

  7. Click here.

  8. Click here to retrieve the information.

  9. Click here.

  10. Click here.

  11. Click here.

  12. Click here

  13. Click here.

  14. <!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 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.<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>

  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 "<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.

  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 "<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

  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 "<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

  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 "<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

More Related