I need to make a web form that adds the information to a database. Currently it takes the information from the textboxes and emails it to one person but what i want is a table of any sort, preferally a databse, that the admin can check that has all the data. here are all the files I have. prodevfrm2.htm
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <title>Default Calendar Web Form To E-Mail</title> <style> <!-- h2 {margin-bottom:.0001pt; text-align:center; page-break-after:avoid; font-size:14.0pt; font-family:"Comic Sans MS"; margin-left:0in; margin-right:0in; ma +rgin-top:0in} h3 {margin-bottom:.0001pt; text-align:center; page-break-after:avoid; font-size:16.0pt; font-family:"Comic Sans MS"; letter-spacing:1.0pt; margin-left:0in; margin-right:0in; margin-to +p:0in} --> </style> </head> <body background="../../gfx/std-bg.jpg" bgcolor="#FFFFFF" text="#000000"> <form action="/perl/prodev.pl" method="POST"> <input type="hidden" name="subject" value="Form To E-Mail System"> <input type="hidden" name="recipient" value="prodev@puyallup.k12.w +a.us"> <input type="hidden" name="link1" value="http://www.puyallup.k12.w +a.us/learning/profdevelopment/main.htm"> <input type="hidden" name="link2" value="Back to the Professional +Development Page"> <div align="center"><center> <table border="0" width="575"> <tr> <td align="center" colspan="3"> <p align="center"><b><font siz +e="5">Professional Development Registration Form</font></b><br> <b><font size="5">Puyallup School District</font></b><font + color="CC0000"> <hr> </td> </tr> <tr> <td width="186"><font face="arial" size="2">Your Name: <input type="text" size="30" name="sendername"> </font></td> <td align="center" width="182"> <p align="left"><font face="ar +ial" size="2">Work Phone: <input type="text" size="30" name="workphone"> </font></td> <td align="center" width="193">&nbsp;</td> </tr> <tr> <td align="left" width="186"><p align="left"> <font face="aria +l" size="2">Your School/Location: <input type="text" size="30" name="location"> </font></p></td> <td align="center" width="182"><p align ="left"> <font face="a +rial" size="2">Home Phone: <input type="text" size="30" name="homephone"> </font></td> <td align="center" width="193">&nbsp;</td> </tr> <tr> <td align="left" width="186"><p align="left"> <font face="aria +l" size="2">Today's Date: <input type="text" size="20" name="todaydate"> </font></p></td> <td align="center" width="182"><p align ="left"> <font face="a +rial" size="2">Your E-mail Address: <input type="text" size="30" name="senderemail"> </font></td> <td align="center" width="193">&nbsp;</td> </tr> <tr> <td align="center" colspan="3"> <p align="left">Please check any that apply to you:<br> <input type="checkbox" name="Classified" value="YES"> Classified&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="checkbox" name="Certified" value="YES"> Certified&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="checkbox" name="Elementary" value="YES"> Elementary&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="checkbox" name="Junior" value="YES"> Junior High<br> <input type="checkbox" name="Senior" value="YES"> Senior High&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="checkbox" name="Dept" value="YES"> Dept <input type="text" name="Deptname" size="12"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="checkbox" name="Other" value="YES"> Other <input type="text" name="Othername" size="13"> <p align="left">I wish to register for the following classes +: (please note class name, session, if applicable, and date of class +)<br> <center> <font size="2" face="arial"> <input type=hidden size="40" name="heading" rows="5"></tex +tarea> </font></p> </td> </tr> <tr> <td width="186"><font face="arial" size="2">Class Name: <input type="hidden" size="30" name="classheader"> </font></td> <td align="center" width="182"> <p align="left"><font face="ar +ial" size="2">Session, if applicable: <input type="hidden" size="30" name="sessionheader"> </font></td> <td align="left" width="193">Date(s) of Class: <input type="hi +dden" size="30" name="dateheader"></td> </tr> <tr> <td width="186"><font face="arial" size="2"> <input type="text" size="30" name="classname1"> </font></td> <td align="center" width="182"> <p align="left"><font face="ar +ial" size="2"> <input name="session1" type="text" id="session1" size="30"> </font></td> <td align="center" width="193"><font face="arial" size="2"> <input name="classdate1" type="text" id="classdate1" size="30"> </font></td> </tr> <tr> <td width="186"><font face="arial" size="2"> <input type="text" size="30" name="classname2"> </font></td> <td align="center" width="182"> <p align="left"><font face="ar +ial" size="2"> <input name="session2" type="text" id="session2" size="30"> </font></td> <td align="center" width="193"><font face="arial" size="2"> <input name="classdate2" type="text" id="classdate2" size="30"> </font></td> </tr> <tr> <td width="186"><font face="arial" size="2"> <input type="text" size="30" name="classname3"> </font></td> <td align="center" width="182"> <p align="left"><font face="ar +ial" size="2"> <input name="session3" type="text" id="session3" size="30"> </font></td> <td align="center" width="193"><font face="arial" size="2"> <input name="classdate3" type="text" id="classdate3" size="30"> </font></td> </tr> <tr> <td width="186"><font face="arial" size="2"> <input type="text" size="30" name="classname4"> </font></td> <td align="center" width="182"> <p align="left"><font face="ar +ial" size="2"> <input name="session4" type="text" id="session4" size="30"> </font></center></td> <td align="center" width="193"><font face="arial" size="2"> <input name="classdate4" type="text" id="classdate4" size="30"> </font></td> </tr> <tr> <td width="186"><font face="arial" size="2"> <input type="text" size="30" name="classname5"> </font></td> <td align="center" width="182"> <p align="left"><font face="ar +ial" size="2"> <input name="session5" type="text" id="session5" size="30"> </font></center></td> <td align="center" width="193"><font face="arial" size="2"> <input name="classdate5" type="text" id="classdate5" size="30"> </font></td> </tr> <tr> <td align="center" colspan="3"><font size="2" face="arial"> <input type="submit" value="Send"> <spacer type="horizontal" size="20"> <input type="reset" value="Clear Form"> </font></td> </tr> </table> </div> </form> <p class="MsoNormal" align="center" style="text-align: center"><b><i> <span style="color:red">Disability Accommodation: Puyallup </span> <span style="color: red">School District</span><span style="color:red"> is committed to +providing access, equal opportunity, and reasonable accommodation in its service +s, programs, education, and professional development activities for indiv +iduals with disabilities.&nbsp; To request disability accommodation, contact +Johnnie McKinley at 253-840-8916 or <a href="mailto:jmckinley@puyallup.k12.wa. +us"> jmckinley@puyallup.k12.wa.us</a></span></i></b></p> <p class="MsoNormal" align="center" style="text-align: center"> <font face="Comic Sans MS"><span style="color: #0000FF"><a href="disab +frm.pdf"> Click here to print a hard copy of the Disability Information form.</a +></span></font></p> <p class="MsoNormal" align="center"><span style="font-size: 11pt"> <font face="Comic Sans MS">Use of these forms requires the Adobe Acrobat Reader.<br> If you need the Adobe Acrobat Reader program click here........<A HREF +="../../../../../../ftp.htm"><IMG SRC="../../gfx/btns/getacro.gif" ALIGN="MIDDLE" BORDER="0" width="88" height="31" NATURALSIZEFLAG="0"></A></p> <p class="MsoNormal" align="center" style="text-align: center">&nbsp;< +/p> <h2 style="margin-top:0in;margin-right:.6in;margin-bottom:0in;margin-l +eft:.5in; margin-bottom:.0001pt"><span style="font-size: 16.0pt">Cancellation of + Classes</span></h2> <p class="MsoNormal" style="margin-top:0in;margin-right:.6in;margin-bo +ttom:0in; margin-left:.5in;margin-bottom:.0001pt"><span style="font-size: 14.0pt +">&nbsp;</span></p> <p class="MsoNormal" align="center" style="margin-top:0in;margin-right +:.6in; margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;text-align:ce +nter"> <span style="font-size: 11.0pt">Each class has a minimum enrollment of + 9 unless otherwise noted.</span></p> <p class="MsoNormal" align="center" style="margin-top:0in;margin-right +:.6in; margin-bottom:0in;margin-left:.5in;margin-bottom:.0001pt;text-align:ce +nter"> <span style="font-size: 11.0pt">If the minimum number of participants +has not registered for a specific class at noon one week before the class star +ting date, the class will be canceled.</span></p> <p class="MsoBlockText">If you registered for a class but find you are + unable to attend, please contact Carolyn Palmer/Professional Development Departm +ent at X8936.</p> <h3>Course Fees</h3> <p class="MsoNormal"><span style="font-size: 11.0pt">Beginning June 7, + there will be <i><span style="color:blue">no charge for clock hours through +</span> </i></span><i><span style="font-size: 11.0pt; color: blue">Puyallup Sc +hool District</span></i><span style="font-size: 11.0pt">; however, there ma +y be charges for materials relating to specific courses.</span></p> <p class="MsoNormal"><span style="font-size: 11.0pt">&nbsp;</span></p> <h3>Registration by Community Members</h3> <p class="MsoBodyText"><span style="font-family:&quot;Comic Sans MS&qu +ot;"> Interested persons outside of the district are welcomed to register on + a space available basis for a non-refundable fee of $35.00.&nbsp; This will be + for registration and materials fee per class.</span></p> <p class="MsoBodyText">&nbsp;</p> </body> </html>
prodev.pl
#!/usr/bin/perl -w # The first line of the file is unnecessary for the Novonyx servers, b +ut is necessary for other # web servers, leave it in to keep the code portable. ################################ # Necessary Fields in HTML Form: # senderemail = specifies the remote users email address for replies # sendername = specifies the remote users real identity # subject = the subject line that will appear in your email # link1 = the url for the link, relative to your web entry point # (ie link1="/index.html") # link2 = the text that will be printed for the link back on the retur +n html page # (ie link2="Back to Wild Things Photography Home") # The first thing that must be printed out to a web page is the follow +ing line. It doesn't # actually print, but it tells the web server what format you will b +e sending it from this # program print "Content-type: text/html\n\n"; # Sendmail is saved as a separate program, so in order to use it, it m +ust be "required" require("sendmail.pl"); # If the requestMethod is "POST", the data will be read from STDIN, # if "GET" it will be read from the URL line $requestMethod = $ENV{"REQUEST_METHOD"}; $input = ""; if($requestMethod eq "POST") { read(STDIN, $input, $ENV{"CONTENT_LENGTH"}); } else { $input = $ENV{'QUERY_STRING'}; } # Strip off white space and any html tags that come in with the form d +ata, and # create an array of the name/value pairs %in = UnencodeFormData(); sendmail(%in); # Print Return HTML # Any reference to graphics of other URLs need the path relative to yo +ur web entry point # If your entry point is sys:/novonyx/suitespot/docs and your graphi +cs are in # ~docs/web/graphics # the url to use is /web/codebreak/graphics/image.jpg print "<html><head><title>Thanks For Your Submission</title></head>\n" +; print "<body><table width=460><tr><td colspan=2>\n"; print "<font face=arial color=#cc3300 size=7><center>Thank You!</font> +\n"; print "<p><hr size=2><font face='comic sans ms' size=2><b>Your submiss +ion has been received.\.<br>\n"; print "Your submission will be reviewed by the Professional Developmen +t Department<br>\n"; print "<hr size=2>\n"; print "</td></tr><tr>\n"; print "<td colspan=2 align=right><font face=arial size=2><a href=$ITEM +{link1}>$ITEM{link2}</a></td></tr>\n"; print "</table>\n"; print "</body></html>"; sub UnencodeFormData { # separate fields @fields = split(/&/, $input); # separate field names from field values foreach $field (@fields) { ($name, $value) = split(/=/, $field); # Convert + signs to spaces, $value =~ tr/+/ /; # convert %HEX values to ASCII characters $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # remove any embedded comments in case of server-side includes $value =~ s/<!--(.|\n)*-->//g; # remove any HTML tags $value =~ s/<([^>]|\n)*>//g; $ITEM{$name} = $value; } # Replace spaces with underscores in the category name # $ITEM{category} = FixCategoryName($UNDERSCORE, $ITEM{category}); return(%ITEM); }
sendmail.pl
#!/usr/bin/perl -w use Socket; use strict; sub sendmail() { my (%body) = @_; my $line = ""; # Substitute your mail server here. my($mailServer) = 'smtp.puyallup.k12.wa.us'; #These next fields come in from the form, your form should have at l +east the following # fields: recipient, senderemail, sendername, subject my($mailTo) = "$body{recipient}"; my($mailFrom) = "$body{senderemail}"; my($realName) = "$body{sendername}"; my($subject) = "$body{subject}"; # These constants shouldn't need changing. my($packFormat) = 'S n a4 x8'; #Internet address format (AF_INET:por +tNumber:serverAddress:eightNulls) my($proto) = getprotobyname("tcp") || 6; my($port) = getservbyname("SMTP", "tcp") || 25; my($name,$aliases,$addrtype,$len,@addrs) = gethostbyname($mailServer +); my($serverAddr) = $addrs[0]; # If this script dies at this line, it is because you don't have an +entry in the SYS:\etc\hosts # file for your mail server. Manually add an entry for the mail se +rver if not already there. if (! defined($len)) { die('gethostbyname failed.'); } socket(SMTP, AF_INET(), SOCK_STREAM(), $proto) or die("socket: $!"); connect(SMTP, pack($packFormat, AF_INET(), $port, $serverAddr)) or die("connect: $!"); select(SMTP); $| = 1; select(STDOUT); # use unbuffered i/o. { my($inpBuf) = ''; recv(SMTP, $inpBuf, 200, 0); } sendSMTP(1, "HELO\n"); sendSMTP(1, "MAIL FROM: <$mailFrom>\n"); sendSMTP(1, "RCPT TO: <$mailTo>\n"); sendSMTP(1, "VRFY\n"); sendSMTP(1, "DATA\n"); sendSMTPnoresponse(1, "From: $realName <$mailFrom>\n"); sendSMTPnoresponse(1, "Subject: $subject\n"); sendSMTPnoresponse(1, "\n"); # Print each of the name/value pairs coming from the form IF they ha +ve been filled in for $line (keys %body) { if($line !~ /link/ && $line !~ /subject/) # We don't need to prin +t out the hidden form fields { sendSMTPnoresponse(1, "$line = $body{$line}\n") if($body{$lin +e}); } } # Since we have put the name/value pairs into a hash which stores ra +ndomly, using the above # for loop will print the name/value pairs randomly in your email +message. # To print them in a specific sequence, you can explicitly print e +ach one with the following # format (INSTEAD OF using the for loop). # sendSMTPnoresponse(1, "Sender\'s Name = $body{sendername}\n") if +($body{sendername}); # sendSMTPnoresponse(1, "Sender\'s Email = $body{senderemail}\n") +if($body{senderemail}); sendSMTPnoresponse(1, "\n"); sendSMTP(1, ".\n"); sendSMTP(1, "QUIT\n"); close(SMTP); } sub closeSocket { # close smtp socket on error close(SMTP); die("SMTP socket closed due to SIGINT\n"); } sub send_to_smtp { my($debug) = shift; my($response) = shift; my($buffer) = @_; # Uncomment the following line for debugging only # print STDERR ("> $buffer") if $debug; send(SMTP, $buffer, 0); if ($response) { recv(SMTP, $buffer, 200, 0); # Uncomment the following line for debugging only # print STDERR ("< $buffer") if $debug; return( (split(/ /, $buffer))[0] ); } } sub sendSMTP { my ($debug) = shift; send_to_smtp($debug, 1, @_); } sub sendSMTPnoresponse { my ($debug) = shift; send_to_smtp($debug, 0, @_); } 1; #return true
This last script is one I found that might work with some modifying, but I don't know how to use it. addline.pl
#!/usr/bin/perl use warnings; use strict; use DBI; use Fcntl qw/:flock/; my $dbh = DBI->connect('DBI:mysql:database=fruits;host=localhost', 'Admin', 'pass', {'RaiseError' => 1}) or die $DBI::errstr; my $query = qq~INSERT INTO table_name (name, count, color, weight) VAL +UES (?, ?, ?, ?)~; my $sth = $dbh->prepare($query); open DATA, "sample.txt"; flock DATA, LOCK_EX; while ( <DATA> ) { chomp; $sth->execute(split /\|/); } close DATA;

In reply to Web Forms and Database by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.