#!/usr/local/bin/perl use CGI qw/:all/; $| = 1; my $q = new CGI; my $action = $q->param('action'); # Read in all the variables set by the form CGI::ReadParse(*input); # Print out a content-type for HTTP/1.0 compatibility print "Content-type: text/html\n\n"; $month = $input{'month'}; $date = $input{'date'}; $year = $input{'year'}; #$action = param('action'); #print $action; $numberoflines = &CountCurrentRecords('events.txt'); if($action eq "add_data"){ print "Your post was sucessful<br>"; #check_event(); add_data(); } else{ #print "We are not in the Add sub-routine<BR>"; #this is just an example fictitious default subroutine } if($action eq "preview"){ #print "<BR>Is this information correct?<br>"; preview(); } else{ #print "We are not in the Preview sub-routine<br>"; #this is just an example fictitious default subroutine } ############### BEGIN COUNTCURRENTRECORDS SUBROUTINE ################# +####### sub CountCurrentRecords { $number = 1; my($database) = ($_[0]); open(DATABASE, "$database"); while ($line=<DATABASE>) { $number++; } $number = 0 if $number < 0; close(DATABASE); return $number; } ###################################################################### +####### ## ## Preview Data Section ## ###################################################################### +###### ############### sub preview ######## sub preview{ print "<html> <HR> <table border='0' width='100%'> <tr> <td width='100%'> <table border='0' width='100%'> <tr> <td width='100%'> <table border='0' width='100%'> <tr> <td width='22%'><font SIZE='+1'color='gray'><B>$month +$date, $year</B></font></td> <td width='78%'><font SIZE='+1'color='black'><B>$input +{'title'}</B></font></td> </tr> </table> </td> </tr> <tr> <td width='100%'><font SIZE='2'>$input{'message'}</font></td +> </tr> </table> </td> </tr> </table> <BR> <form action method='post'> <input type='hidden' name='action' value='add_data'> <input type='submit' value=' Publish new event '> <BR><INPUT type='button' value=' Continue Editing ' onClick='histo +ry.go(-1)'> </form> <BR> $numberoflines </html>\n"; } ###################################################################### +####### ## ## Add Data Section ## ###################################################################### +###### ############### sub add_data ######## sub add_data{ # Print out a content-type for HTTP/1.0 compatibility $addfile = "events.txt"; print "$month"; print $month; #print "We are in the add_data sub-routine<BR>\n"; # Open the file for appending open (OUT, ">>$addfile") or die "Can't open $addfile\n"; $number = $numberoflines; $message = $input{'message'}; $line = join '::', $number,$month,$date,$year,$title,$message; print OUT "$line\n"; close OUT; }
In reply to Re: Re: problem with variable
by cal
in thread problem with variable
by cal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |