Hi,
The following scripts processes the form and write somthings out and then
allow the user to input his/her e-mail address. After input of the e-mail
address, the script write it into a flat file. However, the script runs
into trouble.
Help!
#!/usr/local/bin/perl -wT
use strict;
use CGI;
use Fcntl ":flock";
open (OUTF, ">>db1.txt") || die;
flock(OUTF,2);
seek(OUTF,0,2);
my $q = new CGI;
my( $name, $value );
my $dietary = 0;
foreach $name ( $q->param ) {
print OUTF "$name:";
foreach $value ( $q->param( $name ) ) {
print OUTF " $value |";
if (( $name eq 'q4a' ) || ($name eq 'q4b' ) || ( $name eq 'q4c' ) ||
( $name eq 'q4d' ) ) {
if ($value <= 3) {
$dietary++;
} #end
} #end
}
}
print OUTF "\n";
close(OUTF);
print $q->header( "text/html" );
print $q->start_html( -title => "Survey Result", -bgcolor => "#ff" );
print $q->p( " Survey ");
print $q->hr;
if ( $dietary >= 19 ) {
print $q->p( "Dietary marks count:", $dietary );
print $q->p( " Dietary Habit Health Advice 2 " ) ;
}
if ( $smoking >= 1 ) {
print $q->p( "Health Advice 4, Smoking marks count:", $smoking ) ;
print $q->p( " You have to stop smoking as soon as possible " ) ;
print $q->endform;
&print_prompt($q);
&do_work($q);
print $q->end_html;
sub print_prompt {
my($query) = @_;
print $query->start_form;
print "What's your e-mail address? ";
print $query->textfield('ename');
print ;
print "",$query->reset;
print $query->submit;
print $query->endform;
print "\n";
}
sub do_work {
my($query) = @_;
my($name,$value);
open (OUTF, ">>dbemail.txt") || die;
flock(OUTF,2);
seek(OUTF,0,2);
foreach $name ( $query->param ) {
foreach $value ( $query->param( $name ) ) {
print OUTF "$value\n";
print "Thank you for your enquiries, you'll be contacted
shortly\n";
}
}
close(OUTF);
}
- Original Message -----
From: "Mark Bergeron" <[EMAIL PROTECTED]>
To: "Tat Nam" <[EMAIL PROTECTED]>; "Beginners Perl" <[EMAIL PROTECTED]>
Sent: Tuesday, December 11, 2001 1:06 AM
Subject: Re: cgi & form
> How are you calling the form. You might try and including a little of your
code so we can see what's going on.
>
> -Original Message-
> From: "Tat Nam"<[EMAIL PROTECTED]>
> To: "Beginners Perl"<[EMAIL PROTECTED]>
> Date: Sun Dec 09 23:01:10 PST 2001
> Subject: cgi & form
>
> >Hi,
> > I'm writing a survey form. A cgi program processes the states of the
form and print out somethings and it prompts the user to enter e-mail
address in a text box. The user finishes the input of e-mail address. The
same cgi program will call another cgi program to process the input email
address.
> > I managed to work out the work separately; one cgi program to
manipulate the state of the form, another cgi program to process the email
address. However, when i combined two cgi program into one. It runs into
trouble.
> >
> > Do anybody help on this?
>
>
> ___
> GO.com Mail
> Get Your Free, Private E-mail at http://mail.go.com
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]