Solved

Follow-up CGI Form question

Posted on 1997-04-01
4
204 Views
Last Modified: 2013-12-25
This is a follow-up question to one that a colleague of mine posted and had answered yesterday. It involves the same script which will be attached at the end of this. The form will submit correctly now using this script, but it appears that the counter portion of the script and possibly the writing of the html file are not working properly. When I submit the form it comes back with the info I have
entered and it sends the email informing the list that a new collection has been entered, however, no matter how many times I submit the script it is stuck on Submission #1 and it names the html file ****orphan1.html, instead of increasing both sequentially as it should. I have created the counter.submit file in the working directory as is listed in the counter portion of the script, but this file remains empty, I tried putting a "1" in the file
but it did not do anything. Also the email gives me a url where the new collection can be browsed, but when I go to this directory, there are no files there. The directories all seem to have proper file and directory permissions. Anyone have any suggestions?

#!/opt/gnu/bin/perl
require "cgi-lib.pl";
&ReadParse;              #Read in Variables from Forms

@TIME = split(  "\0", $in{'time'} );                  #These
@TAXA = split(  "\0", $in{'taxa'} );                  #Are
@GEOGRAPHY = split(  "\0", $in{'geography'} );            #Arrays

#Now let's count This Submission

open(COUNTER, "+< /home/WWW/ical/collections/counter.submit");
flock (COUNTER, 2);
$COUNT= <COUNTER>;      #Read the Current Value
$COUNT++;               #Increment Count
seek(COUNTER, 0 , 0);   #Rewind the file
print COUNTER $COUNT;   #Write the Incremented COUNT to file
flock (COUNTER, 8);
close COUNTER;

#Now let's Notify People That Someone Has Made An Addition

open (MAIL, "| /usr/lib/sendmail -oi -t" );
print MAIL <<NOTIFY;
To: ficken\@mobot.org
From:ICALposting\n

      This is a message from ICAL-Botany.
        $in{'name'} has made ICAL Submission #$COUNT for an $in{'type'} collection.
      You can view detailed information on the new collection at:
      http://www.mobot.org/ical/collections/$in{'title'}$in{'type'}$COUNT.html

      This collection covers:
      Time Periods: @TIME
      Taxa: @TAXA
      Geography: @GEOGRAPHY

      Hope you find it interesting!
NOTIFY
close MAIL;

#Let's Put some of this data in a file

open (DATAFILE, ">> /home/WWW/ical/collections/$in{'title'}$in{'type'}$COUNT.html");
flock (DATAFILE, 2);
print DATAFILE <<LIST_TOP;
      <html>
      <head><title>ICAL Submission #$COUNT, $in{'title'}</title></head>
      <body text=#12123F link=#cc6633 vlink=#12123F
            background="http://www.ucmp.berkeley.edu/ICAL/orphback2.gif">
      <h2>Submission #$COUNT, $in{'title'}, is for an $in{'type'} collection and
            comes from $in{'name'}</h2>
      <hr size=3 width=70%>
      <center><font size="+2"><b>Contact Information:</b></font>
      <hr size=3 width=94%>
      <table width=60% border=0>
      <tr><td valign=top align=right>Name:</td>
      <td valign=top><b>$in{'name'}</b></td></tr>
      <tr><td valign=top align=right>Institution:</td>
      <td valign=top><b>$in{'institution'}</b></td></tr>
      <tr><td nowrap valign=top align=right>Postal Address:</td>
      <td valign=top><b>$in{'address'}</b></td></tr>
      <tr><td nowrap valign=top align=right>Phone Number:</td>
      <td valign=top><b>$in{'phone'}</b></td></tr>
      <tr><td nowrap valign=top align=right>Facsimile Number:</td>
      <td valign=top><b>$in{'fax'}</b></td></tr>
      <tr><td nowrap valign=top align=right>Email Address:</td>
      <td valign=top><b><a href=mailto:$in{'email'}>$in{'email'}</a></b></td></tr>
      </table>
      <br>
      <hr size=3 width=70%>
      <table width=94% border=3>
      <tr colspan=3><font size="+2"><b>General Collection
              Attributes:</b></font></tr>
      <tr><td align=center><b>Geologic Age:</b></td>
      <td align=center><b>Taxonomic Coverage:</b></td>
      <td align=center><b>Geographic Range:</b></td></tr>
LIST_TOP

print DATAFILE "<tr><td valign=top>";
foreach $TIME (@TIME) { print DATAFILE "<li>$TIME \n"; }
print DATAFILE "</td>";

print DATAFILE "<td valign=top>";
foreach $TAXA (@TAXA) { print DATAFILE "<li>$TAXA \n"; }
print DATAFILE "</td>";

print DATAFILE "<td valign=top>";
foreach $GEOGRAPHY (@GEOGRAPHY) { print DATAFILE "<li>$GEOGRAPHY \n"; }
print DATAFILE "</td></tr>";

print DATAFILE <<LIST_BOTTOM;
       </table><P>
        <hr width=70% size=3>
        <font size="+2"><B>Specific Collection Attributes</b></font>
        <hr width=94% size=3>
        <table width=94% border=0>

        <tr><td align=right valign=top><b>Collector(s):</b></td>
        <td>$in{'collector'}</td></tr>

        <tr><td align=right valign=top><b>Date(s) Collected:</b></td>
        <td>$in{'date'}</td></tr>

        <tr><td nowrap align=right valign=top><b>Samples in Collection:</b></td>
        <td>$in{'samples'}</td></tr>

        <tr><td nowrap align=right valign=top><b>Volume of Collection:</b></td>
        <td>$in{'volume'}</td></tr>

        <tr><td nowrap align=right valign=top><b>Curatorial Status:</b></td>
        <td>$in{'curatorial'}</td></tr>

        <tr><td nowrap align=right valign=top><b>Geologic Formations:</b></td>
        <td>$in{'geolspecific'}</td></tr>

        <tr><td align=right valign=top><b>Specific Taxa:</b><br></td>
        <td>$in{'taxaspecific'}</td></tr>

        <tr><td nowrap align=right valign=top><b>Specific Localities:</b></td>
        <td>$in{'geogspecific'}</td></tr>

        <tr><td align=right valign=top><b>Other Notes:</b></td>
        <td>$in{'notes'}</td></tr>

        </table>
        </center><P>

      <hr width=70% size=3>
      <center><a href="http://www.ucmp.berkeley.edu/ICAL/"><== Orphan Home</a></center><br>

        <A HREF=http://www.ucmp.berkeley.edu/ICAL/auICAL.html>
        <IMG align=right SRC=http://www.ucmp.berkeley.edu/images/authors.gif
        WIDTH=68 HEIGHT=21></A>
        <A HREF=http://www.ucmp.berkeley.edu/copyright.html>
        <IMG align=right SRC=http://www.ucmp.berkeley.edu/images/copyright.gif
        WIDTH=21 HEIGHT=21></A>
        </body></html>
LIST_BOTTOM
flock (DATAFILE, 8);
close DATAFILE;

#Okay, now let's print out a nice web page for the person who
#just sent in some information on an available list



print "Content-type: text/html\n\n";

print <<TOP;
<html>
<head>
<title>Thank You for submitting $in{'title'} to ICAL</title></head>
<body text=#12123F link=#cc6633 vlink=#12123F
        background="http://www.ucmp.berkeley.edu/ICAL/orphback2.gif">
<center>
<font size="+2"><b>Thank You for Making Submission
      Number $COUNT, $in{'title'}, an $in{'type'} collection
      to<br>ICAL -- Paleontology</b></font>

<hr size=3 width=70%>
<font size="+2"><b>Your Contact Information:</b></font>
<hr size=3 width=94%>

<table width=60% border=0>

<tr><td valign=top align=right>Name:</td>
<td valign=top><b>$in{'name'}</b></td></tr>

<tr><td valign=top align=right>Institution:</td>
<td valign=top><b>$in{'institution'}</b></td></tr>

<tr><td nowrap valign=top align=right>Postal Address:</td>
<td valign=top><b>$in{'address'}</b></td></tr>

<tr><td nowrap valign=top align=right>Phone Number:</td>
<td valign=top><b>$in{'phone'}</b></td></tr>

<tr><td nowrap valign=top align=right>Facsimile Number:</td>
<td valign=top><b>$in{'fax'}</b></td></tr>

<tr><td nowrap valign=top align=right>Email Address:</td>
<td valign=top><b>$in{'email'}</b></td></tr>

</table>
<br>
<hr size=3 width=70%>

<table width=94% border=3>
<tr colspan=3><font size="+2"><b>General Collection
      Attributes:</b></font></tr>
<tr><td align=center><b>Geologic Age:</b></td>
<td align=center><b>Taxonomic Coverage:</b></td>
<td align=center><b>Geographic Range:</b></td></tr>

TOP

print "<tr><td valign=top>";
foreach $TIME (@TIME) { print "<li>$TIME \n"; }
print "</td>";

print "<td valign=top>";
foreach $TAXA (@TAXA) { print "<li>$TAXA \n"; }
print "</td>";

print "<td valign=top>";
foreach $GEOGRAPHY (@GEOGRAPHY) { print "<li>$GEOGRAPHY \n"; }
print "</td></tr>";

print <<FOOTER;

</table><P>
<hr width=70% size=3>
<font size="+2"><B>Specific Collection Attributes</b></font>
<hr width=94% size=3>
<table width=94% border=0>

<tr><td align=right valign=top><b>Collector(s):</b></td>
<td>$in{'collector'}</td></tr>

<tr><td align=right valign=top><b>Date(s) Collected:</b></td>
<td>$in{'date'}</td></tr>

<tr><td align=right valign=top><b>Samples in Collection:</b></td>
<td>$in{'samples'}</td></tr>

<tr><td align=right valign=top><b>Volume of Collection:</b></td>
<td>$in{'volume'}</td></tr>
 
<tr><td align=right valign=top><b>Curatorial Status:</b></td>
<td>$in{'curatorial'}</td></tr>
 
<tr><td align=right valign=top><b>Geologic Formations:</b></td>
<td>$in{'geolspecific'}</td></tr>

<tr><td align=right valign=top><b>Specific Taxa:</b><br></td>
<td>$in{'taxaspecific'}</td></tr>

<tr><td align=right valign=top><b>Specific Localities:</b></td>
<td>$in{'geogspecific'}</td></tr>

<tr><td align=right valign=top><b>Other Notes:</b></td>
<td>$in{'notes'}</td></tr>

</table>
</center><P>

<hr width=70% size=5>
<center><a href="http://www.ucmp.berkeley.edu/ICAL/"><== Orphan Home</a></center><br>

<A HREF=http://www.ucmp.berkeley.edu/ICAL/auICAL.html>
<IMG align=right SRC=http://www.ucmp.berkeley.edu/images/authors.gif  
WIDTH=68 HEIGHT=21></A>
<A HREF=http://www.ucmp.berkeley.edu/copyright.html>
<IMG align=right SRC=http://www.ucmp.berkeley.edu/images/copyright.gif  
WIDTH=21 HEIGHT=21></A>
</body></html>
FOOTER

exit;
0
Comment
Question by:tucker040197
  • 4
4 Comments
 
LVL 5

Accepted Solution

by:
icd earned 100 total points
ID: 1827862
I tried  the counter portion of this script and it worked fine. I think you will find that you do not have world write privileges on the counter.submit file
0
 
LVL 5

Expert Comment

by:icd
ID: 1827863
I tried  the counter portion of this script and it worked fine. Are you sure that the counter.submit file has world read/write permission?
0
 
LVL 5

Expert Comment

by:icd
ID: 1827864
Ooops. That was not supposed to be an answer!
0
 
LVL 5

Expert Comment

by:icd
ID: 1827865
With further tests I find the following.

If your open on COUNTER is as follows

open(COUNTER, "+>/home/WWW/ical/collections/counter.submit");

Then the file is created but it does not increment since it never reads it correctly.

If however it is opened like.

open(COUNTER, "+</home/WWW/ical/collections/counter.submit");

Then the file is not created, but if it exists then it is read correctly and incremented.

In other words, once it had been created correctly by the first type of open the second type would carry on working.

I think this is due to the fact that you are opening the file both for read and write and the file creation is getting screwed up in this case. Either create the file by hand the first time or treat the value of 1 as a special case, close the file and open it write only to write the value of 1.

open(COUNTER, "+</home/WWW/ical/collections/counter.submit");
flock (COUNTER, 2);
$COUNT= <COUNTER>; #Read the Current Value
$COUNT++; #Increment Count
if ($COUNT == 1) {
  close COUNTER;
  open (COUNTER, ">/home/WWW/ical/collections/counter.submit");
}
seek(COUNTER, 0 , 0); #Rewind the file
print COUNTER $COUNT; #Write the Incremented COUNT to file
flock (COUNTER, 8);
close COUNTER;

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question