in reply to Re^3: How to get input text boxes populated
in thread How to get input text boxes populated

Norhing happened, it sends me back to start page where you select the employee to be updated, with following lines for the msg :
Please complete form Debug : action=[UPDATE] empid=[]
Tks Terry

Replies are listed 'Best First'.
Re^5: How to get input text boxes populated
by Anonymous Monk on Jul 07, 2014 at 20:25 UTC

    If you write more subroutine, so instead of having 100 line if/else blocks, you have a single 10-line if else block, and nine 10-line subroutines, you can figure it out why it sends you back to start page instead of updating

    Its very difficult to reason about a 100-line if/else block but a 10-line if/else block is easy, see Re: Adding a pop up confirmation box

    #!/usr/bin/perl -- use strict; use warnings; Main( @ARGV ); sub Main { my $q = CGI->new({ @_ }); my $action = $q->param('go'); if( !defined $action or !length $action ){ return ShowEmployees( $q ); } elsif( $action eq 'confirmDelete' ){ return ConfirmDeleteEmployees( $q ); } elsif( $action eq 'delete' ){ return DeleteEmployees( $q ); } else { return UnrecognizedAction( $q ); }

    Why doesn't employee get updated?

    Does the UpdateEmployee function get called?

    Does the UpdateEmployee function get all the needed arguments/parameters?

    What arguments does UpdateEmployee get?

    Does UpdateEmployee actually work when it gets good args?

    #!/usr/bin/perl -- use strict; use warnings; use CGI; Main( @ARGV ); sub Main { my $q = CGI->new({ @_ }); my $action = $q->param('go'); if( !defined $action or !length $action ){ return ShowEmployees( $q ); } elsif( $action eq 'update' ){ return UpdateEmployee( $q ); } elsif( $action eq 'delete' ){ return DeleteEmployees( $q ); } else { return UnrecognizedAction( $q ); } } sub UpdateEmployee { my( $q ) = @_; my $name = $q->param('name'); my $id = $q->param('id'); print "name($name) id($id)\n"; } __END__ $ perl ogg.pl Undefined subroutine &main::ShowEmployees called at ogg.pl line 9. $ perl ogg.pl go fish Undefined subroutine &main::UnrecognizedAction called at ogg.pl line 1 +5. $ perl ogg.pl go update Use of uninitialized value $name in concatenation (.) or string at ogg +.pl line 22. Use of uninitialized value $id in concatenation (.) or string at ogg.p +l line 22. name() id() $ perl ogg.pl go update name bob Use of uninitialized value $id in concatenation (.) or string at ogg.p +l line 22. name(bob) id() $ perl ogg.pl go update name bob id 77 name(bob) id(77)

    see also another helper sub DebugCGI, see Basic debugging checklist and brian's Guide to Solving Any Perl Problem and write more subs, so you can debug small subs, not giant programs,