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,


In reply to Re^5: How to get input text boxes populated by Anonymous Monk
in thread How to get input text boxes populated by terrykhatri

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.