mnlight has asked for the wisdom of the Perl Monks concerning the following question:

The only thing I can get to the screen is the "Thank you for signing up $name" it doesn't seem to be doing the update as well.
# store subparent for each parent my %parent_hash = ( 'Father' => 'Mother', 'Mother' => 'Father' ); if ( @volunteer_date ){ if (exists $parent_hash{$parent}) { my $sub_parent = $parent_hash{$parent}; for $col ( $parent, $sub_parent ) { $sql = "select $col from Roster where User=?"; $sth = $dbh->selectcol_arrayref( $sql, undef, $user ); if ( @$sth && $sth->[0] ) { # any rows returned? $name = $sth->[0]; # take first one last; } } } print $query->header(), $query->start_html (-title=>'Volunteer List Form', -link=>'#FFFFFF', -vlink=>'#99FF99', -alink=>'black', -style=>{'-src'=>'/CSS/stylesheet.css'}), $query->h1({-align=>'center'},"THANK YOU FOR SIGNING UP $name"); #seperates dates into signed up and duplicate signups. foreach $date ( @volunteer_date ) { $sql = "select distinct Volunteer from Volunteer where Volunte +er =? and Date =?"; my $sth = $dbh->selectcol_arrayref( $sql, undef, $name, $date +); if( @$sth ) { push @dupe_dates, $date; } #end if statement else{ push @signup_dates, $date; } #end else statement } #end foreach loop print $query->start_form('POST', './UnSignup.pl'); #process the signup dates. foreach $signup_date ( @signup_dates ) { my $sql = "select max(Number) from Volunteer where Date =? and + Volunteer = 'TBD'"; my $number = $dbh->selectcol_arrayref($sql, undef, $date); $sql = "update Volunteer set Volunteer = '$name' WHERE Date = +'$date' and Number = $number->[0]"; $sth = $dbh->prepare($sql) || die "prepare: $$sql: $DBI::errst +r"; $sth->execute || die "execute: $sql->[0]: $DBI::errstr"; print $query->start_table({-align=>'center'}), $query->start_Tr({bgcolor=>'#9933FF'}), $query->start_th({-align=>'center', -colspan=>5}), $query->stron +g('VOLUNTEER'), $query->start_th({-align=>'center', -colspan=>5}), $query->stron +g('DATE'), $query->start_th({-align=>'center', -colspan=>5}), $query->stron +g('UNDO'), $query->end_Tr; $query->start_Tr({bgcolor=>'#99FF99'}), $query->start_td({-align=>'center', -colspan=>5}), $query->stron +g($name), $query->start_td({-align=>'center', -colspan=>5}), $query->stron +g($signup_date), $query->start_td({-align=>'center', -colspan=>5}), $query->chec +kbox(-name=>"remove",-value=>$signup_date), $query->end_Tr; print $query->end_table; } #end foreach loop #display the duplicate dates. foreach $dupe_date ( @dupe_dates ) { print $query->h1({-align=>'center'}, "You are already signed up for th +is date: $dupe_date"); } #end foreach loop print $query->center( $query->submit(-name=>'rows', -value=>'Submit'), $query->reset); print $query->end_form(); $sth->finish (); $dbh->disconnect (); } #end if volunteer_date check else{ print $query->h1({-align=>'center'}, "You did not select a dat +e"); } #end else volunteer_date check print $query->h2({-align=>'center'}, $query->a({href=>'../../index.html'}, 'HOME'), '&nbsp', $query->a({href=>'../../Schedule.html'}, 'SCHEDULE'), '&nbsp', $query->a({href=>'Roster.pl'}, 'ROSTER'), '&nbsp', $query->a({href=>'../../News.html'}, 'NEWS'), '&nbsp', $query->a({href=>'../../Pictures.html'}, 'PICTURES'), '&nbsp', $query->a({href=>'UnSignup.pl'}, 'UNDO SIGNUP'), '&nbsp', $query->a({href=>'../BobSchedule.pl'}, 'BOBS SCHEDULE'), '&nbsp' +,); print $query->end_html; print $query->h3({-align=>'center'}, $query->a({href=>'Volunteer.pl'}, 'BACK'), '&nbsp',); print $query->end_html;

Replies are listed 'Best First'.
Re: Why won't my form print to screen
by grep (Monsignor) on Mar 05, 2002 at 07:27 UTC
    The problem you are asking about is:
    $sql = "select distinct Volunteer from Volunteer where Volunteer =? an +d Date =?"; my $sth = $dbh->selectcol_arrayref( $sql, undef, $name, $date );
    You setup the sql statement but never execute it.|
    Update: as particle and jellyfish have pointed out I was off on this. The $dbh handle is undefined at this point.

    You have some other problems in your code that are making it difficult for you to find errors like these.
  • You are not running under warnings, I know this because I spotted you problem when I ran this script under warnings and it gave me Can't call method "selectcol_arrayref" on an undefined value
  • You are also not running under use strict


  • You will find it daunting when you first turn on strict and warnings on this script (I got around 45 errors when I ran your script with warnings and strict), but trust as someone who was in a similar situation, It's not that bad. It'll take you 30 minutes to get rid of those errors, but I will <cajun chef>guarantee</cajun chef> you will save hours of debugging.

    grep
    grep> cd /pub
    grep> more beer

      You setup the sql statement but never execute it.

      Er, isn't that what selectcol_arraryref() does ? - it combines the prepare(),execute and fetch into one method - see the DBI manpage for more on this

      /J\

Re: Why won't my form print to screen
by Trimbach (Curate) on Mar 05, 2002 at 12:58 UTC
    Have you examined the HTML that your program in generating? I mean, you say that the only thing that appears is the "Thank you..." statement. Have you done a "View Source" to see what's actually being output to the browser? I'm asking because you're doing a lot of "start_Th" without a corresponding "end_Th", and "start_td" without "end_td". If you're going to use the special start and end tags in CGI.pm (which you declared with a "use CGI qw(*table *Tr *th *td)" right?) you have to make sure you use the closing tags or your HTML will come out all mangly and stuff and your page won't render.

    Alternatively instead of doing this:

    print $query->start_table({-align=>'center'}), $query->start_Tr({bgcolor=>'#9933FF'}), $query->start_th({-align=>'center', -colspan=>5}), $query->stron +g('VOLUNTEER'), $query->start_th({-align=>'center', -colspan=>5}), $query->stron +g('DATE'), $query->start_th({-align=>'center', -colspan=>5}), $query->stron +g('UNDO'), $query->end_Tr; $query->start_Tr({bgcolor=>'#99FF99'}), $query->start_td({-align=>'center', -colspan=>5}), $query->stron +g($name), $query->start_td({-align=>'center', -colspan=>5}), $query->stron +g($signup_date), $query->start_td({-align=>'center', -colspan=>5}), $query->chec +kbox(-name=>"remove",-value=>$signup_date), $query->end_Tr; print $query->end_table;
    You could do this instead:
    #!/usr/bin/perl use CGI qw(:standard); print table({-align=>'center'}, Tr({bgcolor=>'#9933FF'}, th({-align=>'center', -colspan=>5}, [strong('VOLUNTEER'), strong('DATE'), strong('UNDO')] ) ), Tr({bgcolor=>'#99FF99'}, td({-align=>'center', -colspan=>5}, [strong($name), strong($signup_date), checkbox(-name=>"remove",-value=>$signup_date)] ) ) );
    This does exactly the same thing and it's a lot easier to read (and debug!) as well. You also don't have to worry about the closing tags 'cause CGI.pm will take care of them for you.

    Gary Blackburn
    Trained Killer

Re: Why won't my form print to screen
by particle (Vicar) on Mar 05, 2002 at 12:50 UTC
    your $dbh variable is not initialized. grep pointed indirectly to this. you can't call a method on an uninitialized variable. so that's the source of your error.(or maybe you don't have that error, and it's the source of *his* error)

    there are a few other things:

    $query->start_td(...) should be $query->td(...)
     print $query->end_html; appears more than once. surely you don't mean this...

    i can't back grep's suggestions enough: Use strict warnings and diagnostics or die

    ~Particle ;Þ

      your $dbh variable is not initialized.

      Yeah but neither does the code use DBI; or use CGI; so I would guess that we aren't seeing the whole thing ;-}

      /J\