Code Comments
Programming Forum and web based access to our favorite programming groups.Sorry to post this here too, but comp.infosystems.www.authoring.cgi is lagging by at least 8 hours and I thought someone here might have some ideas. I've got a CGI script running on 2 webservers (apache on 1 server, apache2 on the other), both servers configured for the same functionality. The CGI script (which follows) displays a simple form, which when submitted stores form values in a database and emails them to an email address from the database. This works fine in any browser including IE on the apache2 server. The same script on the apache server (on which all other CGi works) works perfectly in anything other than IE (tested with mozilla and links2). In IE, it displays the form OK, but when submitted displays an IE error page with "Action Cancelled", and doesn't insert a record into the database or perform any other actions. I've got error tracking everywhere it makes sense in the script, but nothing is logged to the apache error log. So... does anyone have any ideas (while I still have some hair left) -- start script -- #!/usr/bin/perl use strict; use DBI; use CGI ':all'; use Env qw/REMOTE_ADDR HTTP_COOKIE/; use CGI::Pretty; use CGI::Carp qw/fatalsToBrowser/; use Mail::Sender; # get username from cookie *e* #***Cookie stuff my %cookie=( 'username' => "", 'auth' => '0' ); my @nvpairs=split(/;/, $ENV{'HTTP_COOKIE'}); foreach my $pair (@nvpairs) { my ($name, $value) = split(/=/, $pair); $name=~ s/ //; $cookie{$name} = $value; } # read form parameters my %params = CGI::Vars(); ######################################## ################################ sub list_depts { # return department list my $dbh = DBI-> connect('DBI:mysql:database=intranet_mis ;user=root') or die "Error connecting to database\n", $DBI::errstr; my $sql = 'SELECT contract_name FROM email_addresses'; my $sth = $dbh->prepare($sql) or die $sql, "\n", $dbh->errstr(); $sth->execute or die $sql, "\n", $sth->errstr(); my @depts; while (my $name = $sth->fetchrow_array()) { push @depts, $name; } $sth->finish(); # add a blank dept to be default selected, so TL has to select something unshift(@depts, ''); return \@depts; } ######################################## ################################ sub form { my $msg = shift(); # list of departments my $depts = list_depts(); # absence types my @absence_types = ("", "Sickness", "Crisis Day", "Compassionate Leave", "Bereavement Leave", "Unauthorised Absence", "Other Authorised Absence"); print header, start_html(-title => 'Request Back To Work Form'), h2('Request Back To Work Form'), "To be completed by line manager/designated duty manager"; if ($msg eq 'missing stuff' and not $params{form}) { print "<font color='#FF0000'>Please fill in all prompts</font>"; } print start_form(), table( Tr([ td(['Payroll Number', textfield(-name => 'payroll_number', -value => $params{payroll_number})]), ]), Tr([ td(['Surname', textfield(-name => 'surname', -value => $params{surname})]), ]), Tr([ td(['Forename', textfield(-name => 'forename', -value => $params{forename})]), ]), Tr([ td(['Department', popup_menu(-name => 'department', -value => [@$depts], -labels => @$depts, -default => $params{department})]), ]), Tr([ td(['Room', textfield(-name => 'room', -value => $params{room})]), ]), Tr([ td(['First Day Of Absence', textfield(-name => 'absence_start', -value => $params{absence_start})]), ]), Tr([ td(['Date Of Return To Work', textfield(-name => 'absence_end', -value => $params{absence_end})]), ]), Tr([ td(['Absence Type', popup_menu(-name => 'absence_type', -value => [@absence_types], -labels => @absence_types, -default => $params{absence_type})]), ]), Tr([ td(['Line manager email address', textfield(-name => 'manager_email', -value => $params{manager_email})]), ]), ), hidden(-name => 'form', -value => 'completed'), submit(-value => 'Post absence'), reset(), end_form, end_html; exit; } ######################################## ################################ my $username = $cookie{username}; my $ip = $ENV{REMOTE_ADDR}; unless ( (scalar(keys %params)) >= 10) { # not completed, redisplay form(); } #### form completed, process my ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday,$isdst) = localtime(time); my $timestr = $year+1900 . '-' . ++$mon . '-' . $mday . ' ' . $hour . ':' . $min . ':' . $sec; # First, insert everything into the database # this looks odd becaue I'm getting DBI to escape special characters my $dbh = DBI-> connect('DBI:mysql:database=intranet_mis ;user=root') or die "Error connecting to database\n", $DBI::errstr; my $sql_insert = "INSERT INTO back_to_work (payroll_no, surname, forename, department, room, absence_start, absence_end, absence_type, manager_email, ip, form_time, giant_username) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; my $sth_insert = $dbh->prepare($sql_insert) or die $sql_insert, "\n", $dbh->errstr(); $sth_insert->execute($params{payroll_number}, $params{surname}, $params{forename}, $params{department}, $params{room}, $params{absence_start}, $params{absence_end}, $params{absence_type}, $params{manager_email}, $ip, $timestr, $username) or die $sql_insert, "\n", $sth_insert->errstr(); # email form values to line manager and MI address # get correct MI address for department my $sql_mis = "SELECT email_address FROM email_addresses WHERE contract_name = '$params{department}'"; my $sth_mis = $dbh->prepare($sql_mis) or die $sql_mis, "\n", $dbh->errstr(); $sth_mis->execute() or die $sql_mis, "\n", $sth_mis->errstr(); my $email_mis = $sth_mis->fetchrow_array(); $sth_mis->finish(); # prep and send email my $msg = " Payroll Number : $params{payroll_number} Surname : $params{surname} Forename : $params{forename} Department : $params{department} Room : $params{room} First Day Of Absence : $params{absence_start} Date Of Return To Work : $params{absence_end} Absence Type : $params{absence_type} Manager's email address : $params{manager_email}"; #foreach my $key (keys %params) { # $msg .= "$key = $params{$key}\n"; #} my $smtp = new Mail::Sender{smtp => '192.168.5.5'}; # thats it, we're out of here *boom* # redirect to somewhere useful print header('text/html'), " <HTML> <HEAD> </head> <body bgcolor=\"#FFFFFF\" text=\"#000000\"> <p> </p> <p align=\"center\"><font size=\"5\">Your Request has been"; $smtp->MailMsg({to => $email_mis, from => $email_mis, cc => $params{manager_email}, msg => $msg, subject => 'Return To Work Form'}); print " sent.</font></p> </body> </html> "; -- Stephen Patterson http://patter.mine.nu/ steveSPAM@.patter.mine.nu remove SPAM to reply Linux Counter No: 142831 GPG Public key: 252B8B37 Caution: breathing may be hazardous to your health.
Post Follow-up to this messageStephen Patterson wrote: > > The same script on the apache server (on which all other CGi works) > works perfectly in anything other than IE (tested with mozilla and > links2). In IE, it displays the form OK, but when submitted displays > an IE error page with "Action Cancelled", and doesn't insert a record > into the database or perform any other actions. I've got error > tracking everywhere it makes sense in the script, but nothing is > logged to the apache error log. There is no sign of this logging here. What does the apache *access_log* say? Was the form submitted? What was the HTTP response code associated with it? Have you consider using a network sniffer to see what actually gets sent across the wire? > use Env qw/REMOTE_ADDR HTTP_COOKIE/; Not the problem, but you don't need this line. You are accessing them using the %ENV hash anyway. *That* line is creating $REMOTE_ADDR and $HTTP_COOKIE in your main namespace as aliases. -- -*- Just because I've written it here doesn't -*- -*- mean that you should, or I do, believe it. -*-
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.